springMVC基于注解开发——命名空间
1、l
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="/2001/XMLSchema-instance" xmlns="/xml/ns/javaee" xsi:schemaLocation="/x ml/ns/javaee /xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>01-springMVCPrimary</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
mvc的controller
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 注册中央调度器 -->
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定springMVC的配置⽂件的位置和路径 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>l</param-value>
</init-param>
<!-- 表⽰启动服务器就创建该对象,不设置的话,那么就在请求到达时,创建该对象 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
2、l
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:context="/schema/context"
xmlns:aop="/schema/aop"
xmlns:tx="/schema/tx"
xsi:schemaLocation="
/schema/beans
/schema/beans/spring-beans.xsd
/schema/context
/schema/context/spring-context.xsd
/schema/tx
/schema/tx/spring-tx.xsd
/schema/aop
/schema/aop/spring-aop.xsd">
<!-- 注册组件扫描器 -->
<context:component-scan base-package="com.handlers"/>
</beans>
3、MyController
package com.handlers;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
@org.springframework.stereotype.Controller
@RequestMapping("/xxx/ooo/jjj") //这就是命名空间
public class MyController {
@RequestMapping(value = {"/first.do", "hello.do"})
public ModelAndView doFirst(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message", "执⾏doFirst()⽅法!");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
@RequestMapping("/second.do")
public ModelAndView doSecond(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView();
mv.addObject("message", "执⾏doSecond()⽅法!");
mv.setViewName("/WEB-INF/jsp/welcome.jsp");
return mv;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。