spring boot hello world 搭建
生活随笔
收集整理的這篇文章主要介紹了
spring boot hello world 搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
1.下載地址:
Eclipse:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neonr
Spring Tool Suite:https://spring.io/tools/sts/all
?
2.使用版本為:
Eclipse:eclipse-jee-neon-R-win32-x86_64.zip
Spring Tool Suite:springsource-tool-suite-3.9.0.RELEASE-e4.6.3-updatesite.zip
?
2.插件安裝:
采用離線安裝,安裝方式類似svn的安裝。
?
3.新建工程:
?
注意,過程中選擇相應的組件,如web,mybatis,redis 等。
?
4.hello?World 代碼的編寫
?共兩個類。
類1:
package com.example.first; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @EnableAutoConfiguration public class Example { @RequestMapping("/") String home() { return "Hello World!"; } @RequestMapping("/hello/{myName}") String index(@PathVariable String myName) { return "Hello "+myName+"!!!"; } }
類 2:
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
?
5.啟動方式
? 右鍵項目名稱,run as application ,選擇上面的Application 類。
?瀏覽器輸入?http://localhost:8080/ ? 即可看到 ?Hello World!
?
轉載于:https://www.cnblogs.com/xzzq/p/7225470.html
總結
以上是生活随笔為你收集整理的spring boot hello world 搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乌镇对外开放时间
- 下一篇: 拿着鸡毛当令箭下一句是什么啊?