我的控制器是
@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] 删除。
我来说两句