简单介绍使⽤springmvc注解的基本流程.1.在web.xml中配置DispatcherServlet
2.创建核⼼配置⽂件springmvc-servlet.xml(WEB-INF/...)
在给配置⽂件中,主要配置注解驱动,配置包扫描就不在配置Bean了(扫描注解),配置视图解析器
xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd\">
3.定义视图(这⾥创建⼀个hello.jsp⽂件,符合上⾯的视图规则,所以要放到WEB-INF/views/)
<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>
${msg }
4.配置handler
@RequestMapping(\"test\")@Controller
public class LoghinController {
@RequestMapping(\"/show1\") public ModelAndView show1(){
ModelAndView mv = new ModelAndView(\"hello\"); mv.addObject(\"msg\第⼀个springmvc程序1\"); return mv; }}}
5.在浏览器输⼊指定的地址,运⾏完成
WEB-INF/{servletName}-servlet.xml
因篇幅问题不能全部显示,请点此查看更多更全内容