我无法再找到我的映射了(我让它工作了。但是,然后,我做了更改,但可能是由于缓存,我没有意识到它何时停止工作:-()。它给出了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;
}
提前多多谢谢你!
答案 0 :(得分:1)
当你使用构造型注释(@ Controller,@ Service,@ Repository)时,最好使用context:component-scan标签来表示Spring必须扫描搜索注释的包并在应用程序上下文中注册bean。 / p>
答案 1 :(得分:0)
我花了好几个小时......发布后,我发现了......
我更改了spring-servlet.xml上的行。按照以前的方式行,它起作用了:
<context:component-scan base-package="my.controller.package" />