天天看點

spring-boot - demo

當我發現把最初的一個demo整的面目全非的時候,突然想要找一個簡單的demo做測試,發現與其在原來的上面該,還不如建立一個demo。

官方入門:http://projects.spring.io/spring-boot/

最熟悉maven,這次先做一個maven的demo。

spring-boot - demo

建立maven project。

pom:

spring-boot - demo
spring-boot - demo

View Code

這裡添加了web基礎依賴,模闆為thymeleaf, 添加一個簡單的security配置。

建立src/resources/application.yml:

建立src/resources/application-dev.yml:

建立啟動入口hello.SampleController:

spring-boot - demo
spring-boot - demo

建立一個Controller: hello.HelloController

spring-boot - demo
spring-boot - demo

這裡連個路由。一個指向模闆檔案index,一個傳回json并添加了參數校驗。

需要使用的實體類:hello.entity.User

spring-boot - demo
spring-boot - demo

需要用到的模闆檔案:src/resources/templates/index.html

spring-boot - demo
spring-boot - demo

github: https://github.com/chenxing12/spring-boot-demo

唯有不斷學習方能改變!

-- <b>Ryan Miao</b>