java - 未找到映射 404 错误 n DispatcherServlet 名称为 'dispatcher'
问题描述
我正在创建小型 crud web 应用程序。我有这个并且它的工作正常,我可以从数据库中保存和读取表,所以这个代码工作:
EmployeeController:
@Controller
@RequestMapping("/employee")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/list")
public String listEmployee(Model theModel) {
// get customers from the service
List<Employee> theEmployee = employeeService.listEmployee();
// add the customers to the model
theModel.addAttribute("employees", theEmployee);
return "list-employee";
}
@GetMapping("/showFormForAdd")
public String showFormForAdd(Model theModel) {
// create model attribute to bind form data
Employee theEmployee = new Employee();
theModel.addAttribute("employee", theEmployee);
return "addNewEmployeeForm";
}
@PostMapping("/addNewEmployee")
public String addNewEmployee(@ModelAttribute("employee") Employee theEmployee) {
// save the customer using our service
employeeService.addNewEmployee(theEmployee);
return "redirect:/employee/list";
}
}
添加新员工部分代码的表格:
<form:form action="addNewEmployee" modelAttribute="employee" method="POST">
该代码工作正常。
这段代码没有,我不知道为什么?
EmployeeDetailController:
@Controller
@RequestMapping("/employeeDetail")
public class EmployeeDetailController {
@Autowired
private EmployeeService employeeService;
@GetMapping("/listEmployeeDetail")
public String listEmployeeDetail(Model theModel) {
// get customers from the service
List<EmployeeDetail> theEmployeeDetail = employeeService.listEmployeeDetail();
// add the customers to the model
theModel.addAttribute("employeeDetails", theEmployeeDetail);
return "list-employeeDetail";
}
@GetMapping("/showFormForAddEmployeeDetail")
public String showFormForAddEmployeeDetail(Model theModel) {
// create model attribute to bind form data
EmployeeDetail theEmployeeDetail = new EmployeeDetail();
theModel.addAttribute("employeeDetail", theEmployeeDetail);
return "addNewEmployeeDetailForm";
}
@PostMapping("/addNewEmployeeDetail")
public String addNewEmployeeDetail(@ModelAttribute("employeeDetail") EmployeeDetail theEmployeeDetail) {
// save the customer using our service
employeeService.addNewEmployeeDetail(theEmployeeDetail);
return "redirect:/employeeDetail/listEmployeeDetail";
}
}
addNewEmployeeDetailForm:
<form:form action="addNewEmployeeDetail" modelAttribute="employeeDetail" method="POST">
我得到这个错误:
No mapping found for HTTP request with URI [/Employee_Tracking_System-1.0-SNAPSHOT/employeeDetail/showFormForAddEmployeeDetail/addNewEmployeeDetail] in DispatcherServlet with name 'dispatcher']]
我没有使用任何 xml,纯干净的 java 配置。我试图把它放在同一个班级,但仍然找不到 404。
解决方案
推荐阅读
- oracle - 907 ORA-00907: 缺少右括号
- java - 将 GoogleSheet 从 Google Driver 复制到 Dropbox
- apache-spark - Spark Coalesce:当错误地在参数中传递了更多分区值时
- mysql - 如何对不同表中的两列求和
- c++ - OpenFOAM 简单 blockMesh 浮点异常
- javascript - 如何在 js 数组映射中声明 typescript 类型?
- mongodb - 对 mongodb 集合中的字段进行字符串操作(聚合和正则表达式)
- clion - 重命名期间 CLion 会搜索系统#include 吗?
- python - 在 pandas 数据框中标记自定义 NER
- javascript - 如何使用javascript仅将字符串中的第一个字母大写?