天天看点

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>