{"id":12255,"date":"2016-12-03T09:00:06","date_gmt":"2016-12-03T00:00:06","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=12255"},"modified":"2018-11-14T16:33:44","modified_gmt":"2018-11-14T07:33:44","slug":"start-with-sts-and-spring-boot-3","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2016\/12\/03\/start-with-sts-and-spring-boot-3\/","title":{"rendered":"Spring Tool Suite (STS)\u3068 Spring Boot \u3067\u59cb\u3081\u308b Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\uff08\uff13\uff09"},"content":{"rendered":"
\u3053\u3093\u306b\u3061\u306f\u3002\u68b6\u539f\u3067\u3059\u3002 \u300cSpring Tool Suite (STS)\u3068 Spring Boot \u3067\u59cb\u3081\u308b Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u300d\u306e\u7b2c3\u56de\u3067\u3059\u3002 Spring Boot<\/a> \u306b\u3064\u3066\u3044\u306f TECHSCORE BLOG \u306e\u8a18\u4e8b\u300cSpring Boot \u5165\u9580<\/a>\u300d\u3082\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n \u524d\u56de\u306e\u8a18\u4e8b\u3067\u306f Spring Tool Suite (STS) \u3067Spring Starter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u5185\u3067\u8a2d\u5b9a\u3057\u305f\u30c6\u30ad\u30b9\u30c8 Hello World \u3092\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u307e\u3057\u305f\u3002 \u524d\u56de\u306e\u8a18\u4e8b\u3067\u4f5c\u6210\u3057\u305f Spring Starter \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u5229\u7528\u3057\u3066\u30d5\u30a9\u30fc\u30e0\u753b\u9762\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 \u524d\u56de\u306e\u8a18\u4e8b\u3067\u306f REST \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4f5c\u6210\u3057\u3001\u30c6\u30ad\u30b9\u30c8\u3092\u30d6\u30e9\u30a6\u30b6\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u307e\u3057\u305f\u3002 \u3068\u3053\u308d\u304c\u3001Spring Boot 1.4.1 \u306e\u30ea\u30d5\u30a1\u30ec\u30f3\u30b9<\/a>\u3092\u78ba\u8a8d\u3059\u308b\u3068\u5229\u7528\u3067\u304d\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u306e\u7a2e\u985e\u306b\u3064\u3044\u3066\u306e\u8a18\u8ff0\u304c\u3042\u308a\u307e\u3059\u304c<\/p>\n JSPs should be avoided if possible, there are several known limitations when using them with embedded servlet containers.<\/em><\/p>\n \u300cJSP \u306f\u53ef\u80fd\u306a\u5834\u5408\u306f\u5229\u7528\u306f\u907f\u3051\u308b\u3079\u304d\u300d\u3068\u3042\u308a\u307e\u3059(\u00b4\u30fb\u03c9\u30fb`) \u5229\u7528\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea Thymeleaf \u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002 \u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067 pom.xml \u304c\u7de8\u96c6\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u30b3\u30e1\u30f3\u30c8\u3067\u300c<!-- \u8ffd\u52a0: \u3053\u3053\u304b\u3089 -->\u300d\u300c<!-- \u8ffd\u52a0: \u3053\u3053\u307e\u3067 -->\u300d\u3068\u66f8\u304b\u308c\u305f\u7bc4\u56f2\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002<\/p>\n \u524d\u56de\u306e\u8a18\u4e8b\u3067\u4f5c\u6210\u3057\u305fHelloController.java \u3092\u7de8\u96c6\u3057\u307e\u3059\u3002 \u30af\u30e9\u30b9\u5b9a\u7fa9\u306e\u524d\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3 \u306f \u524d\u56de\u306e\u8a18\u4e8b\u3067\u306f @RestController \u3067\u3057\u305f\u304c\u3001\u4eca\u56de\u306f @Controller \u3092\u5229\u7528\u3057\u307e\u3059\u3002@RestController \u306f\u30a2\u30af\u30bb\u30b9\u3057\u305f\u5074\u306b\u30c6\u30ad\u30b9\u30c8\u3092\u8fd4\u3059\u3060\u3051\u306e\u52d5\u4f5c\u3067\u3057\u305f\u304c\u3001@Controller \u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066 HTML \u30da\u30fc\u30b8\u3092\u8868\u793a\u3057\u307e\u3059\u3002 \u30d1\u30c3\u30b1\u30fc\u30b8\u30a8\u30af\u30b9\u30d7\u30ed\u30fc\u30e9\u3067\u300csrc\/main\/resources\u300d\u914d\u4e0b\u306b\u3042\u308b\u300ctemplates\u300d\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3057\u3066\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3001New > Other\u2026 \u3092\u30af\u30ea\u30c3\u30af\u3002 \u8a2d\u5b9a\u753b\u9762\u304c\u8d77\u52d5\u3057\u307e\u3059\u3002 \u4fdd\u5b58\u5834\u6240\u306f\u300ctemplates\u300d\u30d5\u30a9\u30eb\u30c0\u3092\u9078\u629e\u3002\u30d5\u30a1\u30a4\u30eb\u540d\u306f\u300cindex.html\u300d\u3092\u5165\u529b\u3057\u3066 Next \u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3002 HTML Template \u306f\u300cNew HTML File (5)\u300d\u3092\u9078\u629e\u3002 Finish \u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u3001index.html \u306e\u4f5c\u6210\u304c\u5b8c\u4e86\u3057\u307e\u3059\u3002 index.html \u3092\u7de8\u96c6\u3057\u3066\u3001\u5165\u529b\u30c6\u30ad\u30b9\u30c8\u6b04\u306b\u5024\u3092\u5165\u529b\u3057\u3066\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u9001\u4fe1\u3055\u308c\u308b\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 please wait...<\/p>\r\n
\n\u3053\u308c\u306f TECHSCORE Advent Calendar 2016<\/a> \u306e3\u65e5\u76ee\u306e\u8a18\u4e8b\u3067\u3059\u3002 <\/p>\n
\n3\u56de\u306b\u5206\u3051\u3066\u63b2\u8f09\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n
\n\u4eca\u56de\u306f\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u3057\u3066\u753b\u9762\u306e\u30d5\u30a9\u30fc\u30e0\u306b\u5165\u529b\u3057\u305f\u5185\u5bb9\u3092\u9001\u4fe1\u3057\u3066\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n\u3053\u306e\u8a18\u4e8b\u306e\u30b4\u30fc\u30eb<\/h2>\n
\n\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u306b\u306f Thymeleaf<\/a> \u3092\u5229\u7528\u3057\u307e\u3059\u3002
\n\u753b\u9762\u306e\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u5165\u529b\u3057\u305f\u5185\u5bb9\u3092\u9001\u4fe1\u3057\u3066\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u307e\u3059\u3002<\/p>\n\u74b0\u5883<\/h2>\n
\n
Spring Boot \u306f JSP \u3092\u63a8\u5968\u3057\u306a\u3044<\/h2>\n
\n\u3057\u304b\u3057\u3001\u5b9f\u969b\u306e Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u3092\u5229\u7528\u3057\u3066\u72ec\u81ea\u30eb\u30fc\u30eb\u3084\u30d7\u30ed\u30b0\u30e9\u30e0\u8a00\u8a9e\u3067\u8a18\u8ff0\u3055\u308c\u305f\u30b3\u30fc\u30c9\u304b\u3089 HTML \u753b\u9762\u3092\u4f5c\u6210\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u753b\u9762\u306b\u8868\u793a\u3055\u305b\u3066\u3044\u307e\u3059\u3002
\nJava \u3067 Web \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306e\u7d4c\u9a13\u304c\u3042\u308b\u65b9\u306f JSP \u3092\u5229\u7528\u3059\u308b\u6a5f\u4f1a\u304c\u591a\u304b\u3063\u305f\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002 <\/p>\n
\n\u305d\u3053\u3067\u3001\u4eca\u56de\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30a8\u30f3\u30b8\u30f3\u306b\u306f Thymeleaf<\/a> \u3092\u5229\u7528\u3057\u3066\u753b\u9762\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\npom.xml \u306e\u7de8\u96c6<\/h2>\n
\nDemoSpringBootApp \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u76f4\u4e0b\u306b\u3042\u308b\u300cpom.xml\u300d\u3092\u53f3\u30af\u30ea\u30c3\u30af\u3057\u3001Open With > Text Editor \u3092\u30af\u30ea\u30c3\u30af\u3002
\n<\/a><\/p>\n
\r\n
\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3092\u4fee\u6b63<\/h2>\n
\n<\/a><\/p>\n
\r\npackage com.techscore.springboot;\r\n \r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class HelloController {\r\n \r\n @RequestMapping(value=\"\/\", method=RequestMethod.GET)\r\n public ModelAndView index(ModelAndView mav) {\r\n mav.setViewName(\"index\");\r\n mav.addObject(\"msg\", \"input your name :\"); \/\/ \u8868\u793a\u30e1\u30c3\u30bb\u30fc\u30b8\r\n return mav;\r\n }\r\n\r\n @RequestMapping(value=\"\/\", method=RequestMethod.POST)\r\n public ModelAndView send(@RequestParam(\"name\")String name, \r\n ModelAndView mav) {\r\n mav.setViewName(\"index\");\r\n mav.addObject(\"msg\", \"Hello \" + name + \" !\"); \/\/ \u8868\u793a\u30e1\u30c3\u30bb\u30fc\u30b8\r\n mav.addObject(\"value\", name); \/\/ \u5165\u529b\u30c6\u30ad\u30b9\u30c8\u306b\u5165\u529b\u5024\u3092\u8868\u793a\r\n return mav;\r\n }\r\n}\r\n<\/pre>\n
\nModelAndView \u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u5229\u7528\u3059\u308b\u30c7\u30fc\u30bf\u985e\u3068\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u540d\u306a\u3069\u30d3\u30e5\u30fc\u306b\u95a2\u3059\u308b\u60c5\u5831\u3092\u307e\u3068\u3081\u3066\u7ba1\u7406\u3059\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/p>\n\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210<\/h2>\n
\n<\/a><\/p>\n
\n\u300cWeb\u300d\u5185\u306e\u300cHTML File\u300d\u3092\u9078\u629e\u3057\u3066 Next \u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3002
\n<\/a><\/p>\n
\n<\/a><\/p>\n
\n<\/a><\/p>\n
\n<\/a><\/p>\n
\n\u5165\u529b\u30c6\u30ad\u30b9\u30c8\u6b04\u306e\u4e0a\u306b\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u304b\u3089\u53d7\u3051\u53d6\u3063\u305f\u5024\u3092\u30e1\u30c3\u30bb\u30fc\u30b8\u3068\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\r\n\r\n\r\n\r\n\r\n