springmvc 使用RESTFul风格的URL

web.xml配置

<!--   spring mvc 拦截器 -->  
  <servlet>  
        <servlet-name>springmvc</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath*:spring/spring-mvc.xml</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>  
    
    
<!--     配置spring resetful -->
    <servlet>  
        <servlet-name>springRESTful</servlet-name>  
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
        <init-param>  
            <param-name>contextConfigLocation</param-name>  
            <param-value>classpath*:spring/spring-mvc.xml</param-value>  
        </init-param>  
    </servlet>  
  
    <servlet-mapping>  
        <servlet-name>springRESTful</servlet-name>  
        <url-pattern>/</url-pattern>  
    </servlet-mapping>  

springmvc.xml配置

    
<!--     使用RESTFul风格时对静态资源的访问 -->
	<mvc:resources location="/js/" mapping="/js/**"/>
	<mvc:resources location="/css/" mapping="/css/**"/>
	<mvc:resources location="/images/" mapping="/images/**"/>
    

接着在ACTION里配置

	//id跟是把页面传来的数据匹配绑定到参数上 
	@RequestMapping("/gUserInfo/{id}")
	public @ResponseBody TUserinfo gUserinfo(@PathVariable("id") String user) throws Exception {
		TUserinfo u = userService.findByUserName(user);
		
		return u;
	}
	

页面上直接访问xxx/gUserInfo/id就可以了

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/samrtian/article/details/79963821
文章标签: springmvc RESTFul
个人分类: springmvc
上一篇springmvc 使用json交互数据 (ajax)
下一篇springmvc 自定义的拦截器
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭