{"id":210246,"date":"2021-01-26T10:00:18","date_gmt":"2021-01-26T02:00:18","guid":{"rendered":"https:\/\/gulass.cn\/?p=210246"},"modified":"2021-01-24T15:03:39","modified_gmt":"2021-01-24T07:03:39","slug":"controller-rest-difference","status":"publish","type":"post","link":"https:\/\/gulass.cn\/controller-rest-difference.html","title":{"rendered":"Controller\u548cRestController\u7684\u533a\u522b"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5728springboot\u4e2d\uff0cController, RestController\u662f\u4f7f\u7528\u63a7\u5236\u5668\u6700\u5e38\u7528\u7684\u4e24\u4e2a\u6ce8\u89e3\uff0c\u4f46\u662f\u4e24\u8005\u4e4b\u5bb6\u7684\u5dee\u5f02\u4f60\u77e5\u9053\u5417\uff1f\u672c\u6587\u5c31\u662f\u8981\u8bb2\u8ff0\u4e24\u8005\u4e4b\u95f4\u7684\u533a\u522b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n 1. Controller, RestController\u7684\u5171\u540c\u70b9<\/strong><\/div>\n \u90fd\u662f\u7528\u6765\u8868\u793aSpring\u67d0\u4e2a\u7c7b\u7684\u662f\u5426\u53ef\u4ee5\u63a5\u6536HTTP\u8bf7\u6c42\u3002<\/p>\n 2. Controller, RestController\u7684\u4e0d\u540c\u70b9<\/strong><\/div>\n @Controller\uff1a\u6807\u8bc6\u4e00\u4e2aSpring\u7c7b\u662fSpring MVC controller\u5904\u7406\u5668,@RestController\uff1a@RestController\u662f@Controller\u548c@ResponseBody\u7684\u7ed3\u5408\u4f53\uff0c\u4e24\u4e2a\u6807\u6ce8\u5408\u5e76\u8d77\u6765\u7684\u4f5c\u7528\u3002@Controller\u7c7b\u4e2d\u7684\u65b9\u6cd5\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u8fd4\u56deString\u8df3\u8f6c\u5230jsp\u3001ftl\u3001html\u7b49\u6a21\u7248\u9875\u9762\u3002\u5728\u65b9\u6cd5\u4e0a\u52a0@ResponseBody\u6ce8\u89e3\uff0c\u4e5f\u53ef\u4ee5\u8fd4\u56de\u5b9e\u4f53\u5bf9\u8c61\u3002@RestController\u7c7b\u4e2d\u7684\u6240\u6709\u65b9\u6cd5\u53ea\u80fd\u8fd4\u56deString\u3001Object\u3001Json\u7b49\u5b9e\u4f53\u5bf9\u8c61\uff0c\u4e0d\u80fd\u8df3\u8f6c\u5230\u6a21\u7248\u9875\u9762\u3002<\/p>\n @RestController\u4e2d\u7684\u65b9\u6cd5\u5982\u679c\u60f3\u8df3\u8f6c\u9875\u9762\uff0c\u5219\u7528ModelAndView\u8fdb\u884c\u5c01\u88c5\uff0c\u5982\u4e0b\uff1a<\/p>\n \r\n@RestController\r\npublic class UserController {\r\n\r\n @RequestMapping(value = \"\/index\",method = RequestMethod.GET)\r\n public String toIndex(){\r\n ModelAndView mv = new ModelAndView(\"index\");\r\n \treturn mv; \r\n }\r\n}\r\n \r\n<\/pre>\n |