idea版本:ideaIU-2017.2.1.exehtml
源碼地址:quickStartjava
補充:git
使用idea建立spring-boot工程github
1)http://start.spring.io/,點擊Generate Projectweb
2)使用idea導入生成工程spring
工程結構目錄json
<!--添加web模塊--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!--熱啓動--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
author.name=小王
public class PropertiesValues { @Value("${author.name}") private String userName; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } }
@RestController public class UserController { @Autowired private PropertiesValues propertiesValues; @RequestMapping("getUser.do") public User getUser(){ User user = new User(); user.setName(propertiesValues.getUserName()); user.setSex(1); return user; } }
運行QuickStartApplication.java中main方法springboot
地址:localhost:8080/getUser.doapp
返回:ide
{"name":"小王","sex":1}