连接前端与后端

用户8994147

我的控制器是

@RestController 公共类 MainRestController {

@Autowired
private EmployeeDAO employeeDAO;
private final Logger logger = LoggerFactory.getLogger(MainRestController.class);

@RequestMapping("/")
public String newHome(Model Employee){
    return "newHome";
}

// call http://<host>/newHome.jspjsp or just http://<host>/hello
/*
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String newHome(Model employee) {
    employee.addAttribute("myObject", new MyObject("helloWorld"));
    return "newHome";
}

*/ @RequestMapping(value = "/employee", method = RequestMethod.GET, products = {MediaType.APPLICATION_JSON_VALUE}) public JSONObject getEmployees(){

    return employeeDAO.getAllEmployees();
}

@RequestMapping(value = "/employee/{empName}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })

public JSONObject getEmployee(@PathVariable("empName") String empName) {
    return employeeDAO.getEmployee(empName);
}

@RequestMapping(value = "/employee", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE})

public Employee addEmployee(@RequestBody Employee emp) {

    return employeeDAO.addEmployee(emp);

}

@RequestMapping(value = "/employee", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE})
public Employee updateEmployee(@RequestBody Employee emp) {

    return employeeDAO.updateEmployee(emp);
}

@RequestMapping(value = "/employees/{empName}", method = RequestMethod.DELETE, produces = { MediaType.APPLICATION_JSON_VALUE })
public void deleteEmployee(@PathVariable("empName") String empName) {
    employeeDAO.deleteEmployee(empName);
}

@RequestMapping(value = "/newHome", method = RequestMethod.GET)
public Employee newEmployee(){
    Employee employee = new Employee();
    employee.setEmpName("newHome");
    return employee;
} }

我的java文件是:

公共类 ReadExcelFileAndStore {

public List getTheFileAsObject(String filePath){

    List <Employee> employeeList = new ArrayList<>();

    try {

        FileInputStream file = new FileInputStream(new File(filePath));

        // Get the workbook instance for XLS file
        HSSFWorkbook workbook = new HSSFWorkbook(file);

        int numberOfSheets = workbook.getNumberOfSheets();
        //loop through each of the sheets
        for (int i = 0; i < numberOfSheets; i++) {

            // Get first sheet from the workbook
            HSSFSheet sheet = workbook.getSheetAt(i);

            // Iterate through each rows from first sheet
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) {
                // Get Each Row
                Row row = rowIterator.next();

                //Leaving the first row alone as it is header

                if (row.getRowNum() == 0)
                    continue;

                // For each row, iterate through each columns
                Iterator<Cell> cellIterator = row.cellIterator();

                Employee employee = new Employee();

                while (cellIterator.hasNext()) {

                    Cell cell = cellIterator.next();

                    int columnIndex = cell.getColumnIndex();

                    switch (columnIndex + 1) {

                        case 1:
                            employee.setEmpName(cell.getStringCellValue());
                            break;
                        case 2:
                            employee.setExtCode((int) cell.getNumericCellValue());
                            break;
                    }
                }
                employeeList.add(employee);
            }
        }
        file.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return employeeList;
} }

我关注了一些关于在控制器中提供静态内容的网站,并添加了 JSP 和 JSP 文件中包含的标签所需的依赖项。但是即使我有 JSP 文件要链接,我仍然没有将前端与后端连接起来。我需要添加什么才能将我的前端与后端连接起来。请知道的人分享您的答案。谢谢

停车处

您的 src/main 文件夹中可能有一个名为 resources 的文件夹。创建一个名为 static 或 public 的新文件夹,并将您的 html 页面放在 static 或 public 文件夹中。如果从索引页开始,则不需要创建单独的映射。希望这是您正在寻找的答案。更多知识请参考他的链接:https : //spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将后端与前端连接时已释放连接错误

来自分类Dev

将后端与前端连接时已释放连接错误

来自分类Dev

如何将前端HTML / JQuery连接到后端Python

来自分类Dev

BDD周期-如何将后端与前端连接

来自分类Dev

我正在尝试将Azure后端与离子角前端连接

来自分类Dev

使用自签名证书的安全前端连接到后端

来自分类Dev

使用Flask将Python后端与Flutter前端连接

来自分类Dev

如何连接Express后端和Next.js前端?

来自分类Dev

我正在尝试将Azure后端与离子角前端连接

来自分类Dev

无法在 kubernetes 中将前端应用{Angular} 连接到后端{SpringBoot}

来自分类Dev

检查前端和后端

来自分类Dev

前端和后端与快递

来自分类Dev

前端模板与后端模板

来自分类Dev

前端还是后端加密?

来自分类Dev

前端后端类交换

来自分类Dev

AWS 前端后端通信

来自分类Dev

SQL Server后端和访问前端-与SQL Server本机客户端的ODBC连接失败

来自分类Dev

如何在本地应用程序中连接前端(js)和后端(php)?

来自分类Dev

我在连接正在制作的书店GUI的前端和后端时遇到问题

来自分类Dev

如何连接Vue.js作为前端和Fastapi作为后端

来自分类Dev

如何将后端(python,flask)与前端(html,css,javascript)连接

来自分类Dev

laravel中的后端/前端分离

来自分类Dev

前端后端通信iOS应用

来自分类Dev

修剪空白-前端还是后端?

来自分类Dev

单缓存前端和后端

来自分类Dev

前端和后端之间的HTTPS

来自分类Dev

从后端到前端获取价值

来自分类Dev

在后端通知前端更改

来自分类Dev

前端后端通信iOS应用