
{"id":2692,"date":"2020-12-13T14:10:01","date_gmt":"2020-12-13T06:10:01","guid":{"rendered":"http:\/\/127.0.0.2\/?p=2692"},"modified":"2021-01-05T14:10:27","modified_gmt":"2021-01-05T06:10:27","slug":"2020java%e6%a1%86%e6%9e%b6%e6%95%99%e7%a8%8b%e4%b9%8bspring%e7%9a%84restful","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2692","title":{"rendered":"2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u7684RESTful"},"content":{"rendered":"<h3>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u7684RESTful<\/h3>\n<p>REST<\/p>\n<p>REST\uff1a\u5373<span style=\"color: #ff0000;\">Representational State Transfer<\/span>\uff0c(\u8d44\u6e90)\u8868\u73b0\u5c42\u72b6\u6001\u8f6c\u5316\u3002<br \/>\n\u662f\u76ee\u524d\u6700\u6d41\u884c\u7684\u4e00\u79cd\u4e92\u8054\u7f51\u8f6f\u4ef6\u67b6\u6784\u3002<br \/>\n\u5b83\u7ed3\u6784\u6e05\u6670\u3001\u7b26\u5408\u6807\u51c6\u3001\u6613\u4e8e\u7406\u89e3\uff0c\u6269\u5c55\u65b9\u4fbf\uff0c\u6240\u4ee5\u6b63\u5f97\u5230\u8d8a\u6765\u8d8a\u591a\u7f51\u7ad9\u7684\u91c7\u7528\u3002<\/p>\n<p>\u5177\u4f53\u8bf4\uff0c\u5c31\u662fHTTP\u534f\u8bae\u91cc\u9762\uff0c\u56db\u4e2a\u8868\u793a\u64cd\u4f5c\u65b9\u5f0f\u7684\u52a8\u8bcd\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">GET\u3001POST\u3001PUT\u3001DELETE<\/span><\/p>\n<p>\u5b83\u4eec\u5206\u522b\u5bf9\u5e94\u56db\u79cd\u57fa\u672c\u64cd\u4f5c\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">GET \u7528\u6765\u83b7\u53d6\u8d44\u6e90<\/span><br \/>\n<span style=\"color: #ff0000;\">POST \u7528\u6765\u65b0\u5efa\u8d44\u6e90<\/span><br \/>\n<span style=\"color: #ff0000;\">PUT \u7528\u6765\u66f4\u65b0\u8d44\u6e90<\/span><br \/>\n<span style=\"color: #ff0000;\">DELETE \u7528\u6765\u5220\u9664\u8d44\u6e90<\/span><\/p>\n<p><!--more--><\/p>\n<p>URL\u793a\u4f8b\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">\/target\/1\u00a0 HTTP GET: \u5f97\u5230 id=1 \u7684order<\/span><br \/>\n<span style=\"color: #ff0000;\">\/target\/1\u00a0 HTTP DELETE: \u5220\u9664id=1\u7684order<\/span><br \/>\n<span style=\"color: #ff0000;\">\/target\/1\u00a0 HTTP PUT \uff1a\u66f4\u65b0id=1\u7684order<\/span><br \/>\n<span style=\"color: #ff0000;\">\/target\/1\u00a0 HTTP POST\uff1a\u65b0\u589eorder<\/span><\/p>\n<p><span style=\"color: #ff0000;\">HiddenHttpMethodFliter<\/span>\uff1a\u6d4f\u89c8\u5668form\u8868\u5355\u53ea\u652f\u6301 GET \u548c POST \u8bf7\u6c42\uff0c\u4e0d\u652f\u6301DELETE\u3001PUT \u8bf7\u6c42\uff0c<br \/>\nspring\u6dfb\u52a0\u4e00\u4e2a\u8fc7\u6ee4\u5668\uff0c\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u8bf7\u6c42\u8f6c\u6362\u4e3a\u6807\u51c6\u7684 http\u65b9\u6cd5\uff0c\u652f\u6301GET\u3001POST\u3001PUT\u548cDELETE\u8bf7\u6c42\u3002<\/p>\n<h3>\u521b\u5efaRESTful\u5e94\u7528\u7a0b\u5e8f<\/h3>\n<p><strong>1\u3001\u914d\u7f6e\u8fc7\u6ee4\u5668<\/strong><\/p>\n<pre>&lt;filter&gt;\r\n  &lt;filter-name&gt;HiddenHttpMethodFilter&lt;\/filter-name&gt;\r\n  &lt;filter-class&gt;org.springframework.web.filter.HiddenHttpMethodFilter&lt;\/filter-class&gt;\r\n&lt;\/filter&gt;\r\n&lt;filter-mapping&gt;\r\n  &lt;filter-name&gt;HiddenHttpMethodFilter&lt;\/filter-name&gt;\r\n  &lt;url-pattern&gt;\/*&lt;\/url-pattern&gt;\r\n&lt;\/filter-mapping&gt;<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/13\/2.png\" alt=\"\" width=\"680\" \/><\/p>\n<p><strong>\u5b9e\u73b0delete\u63d0\u4ea4<\/strong><\/p>\n<p><span style=\"color: #ff0000;\">jsp\uff1a<\/span><\/p>\n<pre>&lt;a href=\"javascript:void(0)\" onclick=\"deleteById()\"&gt;\u5220\u9664&lt;\/a&gt;\r\n&lt;a href=\"javascript:void(0)\" onclick=\"updateById()\"&gt;\u4fee\u6539&lt;\/a&gt;\r\n&lt;form action=\"1\" method=\"post\" id=\"deleteForm\"&gt;\r\n    &lt;input type=\"text\" name=\"_method\" value=\"DELETE\"&gt;\r\n    &lt;button&gt;\u5220\u9664&lt;\/button&gt;\r\n&lt;\/form&gt;\r\n&lt;form action=\"1\" method=\"post\" id=\"updateForm\"&gt;\r\n    &lt;input type=\"text\" name=\"_method\" value=\"PUT\"&gt;\r\n    &lt;button&gt;\u4fee\u6539&lt;\/button&gt;\r\n&lt;\/form&gt;\r\n&lt;script&gt;\r\n    function deleteById(){\r\n        document.getElementById('deleteForm').submit();\r\n    }\r\n    function updateById(){\r\n        document.getElementById('updateForm').submit();\r\n    }\r\n&lt;\/script&gt;<\/pre>\n<p><span style=\"color: #ff0000;\">controller\uff1a<\/span><\/p>\n<pre>@RequestMapping(value = \"admin\/list\",method = RequestMethod.GET)\r\npublic String list(){\r\n    return \"admin\/list\";\r\n}\r\n@RequestMapping(value = \"admin\/{id}\",method = RequestMethod.DELETE)\r\npublic String delete(){\r\n    System.out.println(\"\u6267\u884c\u5220\u9664\uff0c\u5df2\u5220\u9664\");\r\n    return \"redirect:\/admin\/list\";\r\n}\r\n@RequestMapping(value = \"admin\/{id}\",method = RequestMethod.PUT)\r\npublic String update(){\r\n    System.out.println(\"\u6267\u884c\u4fee\u6539\uff0c\u5df2\u4fee\u6539\");\r\n    return \"redirect:\/admin\/list\";\r\n}<\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/13\/1.jpg\" alt=\"\" width=\"680\" \/><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2254\" src=\"\/wp-content\/uploads\/2020\/12\/13\/1.png\" alt=\"\" width=\"680\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020java\u6846\u67b6\u6559\u7a0b\u4e4bspring\u7684RESTful REST REST\uff1a\u5373Representational [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2692","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2692"}],"version-history":[{"count":5,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2692\/revisions"}],"predecessor-version":[{"id":2702,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2692\/revisions\/2702"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}