• restful风格。Springmvc


    1. restful风格。Springmvc 

    Localhost:8080/springmvc-01/user

    Method=”post”

    Uri:资源的形式传递到后台。

    Delete 删除. Localhost:8080/springmvc-01/user/3

    Get:查询操作 Localhost:8080/springmvc-01/user/1

    Post:添加Localhost:8080/springmvc-01/user

    Put:修改 Localhost:8080/springmvc-01/user

    1. 请求地址http://localhost:8080/Springmvc-04/user/6
    2. 控制层会根据你的请求方式调用不同的方法。

     

     1     //1赋值给了{uid}了
     2     @RequestMapping(value="{uid}",method=RequestMethod.GET)    //method:表示该方法处理get请求
     3     public String findBuId(@PathVariable("uid") int id) {    //@PathVariable
     4         System.out.println("===----------finById"+id);
     5         return "index";
     6     }
     7     
     8     @RequestMapping(value="uid",method=RequestMethod.POST)//添加操作
     9     public String inSertUser(@PathVariable("uid")int id, Users user) {
    10         System.out.println(user);
    11         return "index";
    12     }

    提交方式:PUTdelete.

    1. web.xml文件中配置过滤器.

     1 <!-- 
     2       把post请转化为put 和delete 请求
     3       使用_method表示真正的提交方式
     4    -->
     5   <filter>
     6           <filter-name>hiddenHttpMethodFilter</filter-name>
     7           <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
     8   </filter>
     9   <filter-mapping>
    10           <filter-name>hiddenHttpMethodFilter</filter-name>
    11           <url-pattern>/*</url-pattern>
    12   </filter-mapping>
    1. 控制层中。

     1     @RequestMapping(method=RequestMethod.PUT)//
     2     @ResponseBody
     3     public String updateUser(Users user) {
     4         System.out.println(user+"update");
     5         return "index";
     6     }
     7     
     8     @RequestMapping(value="{uid}",method=RequestMethod.DELETE)//
     9     @ResponseBody
    10     public String delete(@PathVariable int id) {
    11         System.out.println(id+"-======delete");
    12         return "index";
    13     }
    1. 页面

  • 相关阅读:
    输入函数
    pe结构讲解
    pe结构讲解
    小甲鱼pe结构讲解
    pe结构讲解
    pe结构讲解
    YUI3学习笔记 ( 7 )
    [转载 css]用CSS调整scrollbar(滚动条)的配色
    [转载 js]一次性解决png在i6下的透明问题(包括做为img和背景的两种情况)
    YUI3学习笔记 ( 7 )
  • 原文地址:https://www.cnblogs.com/banzhuanlaowang/p/11462664.html
Copyright © 2020-2023  润新知