1、确定属性值
application.properties
server.port=8989
server.servlet.context-path=/springboot_day3
user.id=21
user.age=23
name=xiaochen
bir=2012/12/12 12:12:12
strs=aa,bb,cc
qqs=xiaochen,xiaohei,xiaoming
maps={'aa':'xiaochen','bb':'xiaohei','cc':'xiaosan'}
2、属性注入
HelloController
@Controller
@RequestMapping("hello")
public class HelloController {
@Value("${name}")
private String name;
@Value("${server.port}")
private int port;
@Value("${bir}")
private Date bir;
@Value("${strs}") //数组
private String[] strs;
@Value("${qqs}") //list
private List<String> qqs;
@Value("#{${maps}}") //maps
private Map<String,String> maps;
@Autowired
private User user; //对象的注入
@GetMapping("hello1")
public String hello1(){
System.out.println("hello springboot");
System.out.println("name = " + name);
System.out.println("port = " + port);
System.out.println("bir = " + bir);
for (String str : strs) {
System.out.println(str);
}
qqs.forEach(qq-> System.out.println("qq = " + qq));
maps.forEach((k,v)-> System.out.println("k=" + k+" v="+v));
System.out.println("user = " + user);
return "hello springboot !!!";
}
}