我不能找到我的映射了(我使它工作。但后来,我做了一些改变,但可能是由于缓存,我没有意识到它什么时候停止工作:-()。现在当我点击表单上的提交时,它给出了404错误。任何帮助都会很感激。提前感谢!
web . xml:
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
JSP: <form:form method="POST" action="/app/app/studentSearchById" commandName="student">
控制器:
@Controller
// @RequestMapping("/studentSearch")
public class StudentSearchController {
// @Autowired
//StudentService userService = new StudentService();
// @RequestMapping(value="/StudentSearchById", method = RequestMethod.GET)
// public ModelAndView searchById(@PathVariable Long studentId) {
@RequestMapping(value = "/studentSearchById", method = RequestMethod.POST)
public ModelAndView searchById(@ModelAttribute("student") Student student, Map<String, Object> map,
HttpServletRequest request) {
StudentService userService = new StudentService();
Student studentFound = userService.findStudent(student.getStudentId());
ModelAndView modelAndView = new ModelAndView();
// modelAndView.addObject("students", studentFound);
return modelAndView;
}
提前谢谢你!
当你使用构造型注释(@Controller, @Service, @Repository)时,最好使用context: component-scan标签来说明Spring必须扫描包,搜索注释并在应用程序上下文中注册bean。
我花了几个小时……就在发帖之后,我发现了…
我已经更改了spring-servlet.xml中的行。像以前一样输入这行代码,它就成功了:
<context:component-scan base-package="my.controller.package" />