首页 > 其他 > 详细

Restful风格编码

时间:2021-09-06 07:56:21      阅读:11      评论:0      收藏:0      [点我收藏+]

web.xml所需配置:

 

                        

  <filter>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <servlet-name>DispatcherServlet</servlet-name>
  </filter-mapping>

  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:spring-mvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

页面配置:

      

<form action="/rest/rest/100" method="post">
<input type="hidden" name="_method" value="put">
<input type="submit">
</form>

测试代码:

package com.xysf.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;

//@Controller
//@ResponseBody
@org.springframework.web.bind.annotation.RestController
@RequestMapping("rest")
public class RestController {
    @RequestMapping("rest1")
    public String  rest1(){
        return "save.jsp";
    }
    @RequestMapping("{id}")
    public String  rest1(@PathVariable Integer id){
        System.out.println("变量:"+id);
        return "save.jsp";
    }
    @PutMapping("{id}")
    public String  rest2(@PathVariable Integer id){
        System.out.println("变量:"+id);
        System.out.println("put");
        return "save.jsp";
    }
}

 

      

Restful风格编码

原文:https://www.cnblogs.com/waacode/p/15226780.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!