日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot-web开发(rest风格支持)

發布時間:2025/6/15 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot-web开发(rest风格支持) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?rest風格支持(使用http請求方式動詞來標識對資源的操作)

<html><head><meta charset="UTF-8"> </head><body><form action="/user" method="get"><input value="rest-get 提交" type="submit"></form><form action="/user" method="post"><input value="rest-post 提交" type="submit"></form><form action="/user" method="post"><input name="_method" type="hidden" value="DELETE"><input value="rest-delete 提交" type="submit"></form><form action="/user" method="post"><input name="_method" type="hidden" value="PUT"><input value="rest-put_method 提交" type="submit"></form><form action="/user" method="post"><!-- 自定義參數名稱 --><input name="_m" type="hidden" value="PUT"><input value="rest-put_m 提交" type="submit"></form> </body></html> package com.atchina.boot.controller;import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController;@RestController public class HelloController {@RequestMapping(value = "/user",method = RequestMethod.GET)public String getUser(){return "GET user";}@RequestMapping(value = "/user",method = RequestMethod.POST)public String saveUser(){return "POST user";}@RequestMapping(value = "/user",method = RequestMethod.PUT)public String putUser(){return "PUT user";}@RequestMapping(value = "/user",method = RequestMethod.DELETE)public String deleteUser(){return "DELETE user";} } import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.filter.HiddenHttpMethodFilter;@Configuration public class WebConfig {@Beanpublic HiddenHttpMethodFilter hiddenHttpMethodFilter(){HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();// 可以自定義restful風格的methodParamhiddenHttpMethodFilter.setMethodParam("_m");return hiddenHttpMethodFilter;} }

核心Filter:HiddenHttpMethodFilter? 會對 _method的參數進行解析。

?我們要想使用系統提供的這個filter,那么這個屬性就要我們手工開啟。默認是false,不開啟。

總結

以上是生活随笔為你收集整理的springboot-web开发(rest风格支持)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。