springboot(2)
实现在application.yaml中进行赋值的操作
Person.class
@ConfigurationProperties(prefix = "person")//容器中对person进行绑定这样在yaml中就可以直接赋值了
@Component //放入容器中
@Data //自动创建get set方法
@ToString
public class Person {
private String userName;
private Boolean boss;
private Date birth;
private Integer age;
private Pet pet;
private String[] interests;
private List<String> animal;
private Map<String,Object> score;
private Set<Double> salarys;
private Map<String,List<Pet>> allpets;
}
application.yml 赋值的格式
person:
userName: zhangsan
boss: true
birth: 2019/12/9
age: 18
#interests: [篮球,足球] 行内写法
interests:
- 篮球
- 足球
- 18
animal: [啊毛,阿狗]
score:
english: 80
math: 90
salarys:
- 9999
- 88888
pet:
name: zhangs
weight: 32
allpets:
sick:
- {name: sss,weight: 99}
- name: 澳毛
weight: 336
health:
- name: jiangkang
weight: 66
ps:本来很简单,但是却在运行器报错,因为birth是date类型我写成了data提示我转型错误唉, 还有就是 name: 1 一定要有空格。
name="sfs \n 44" 会空行, 单引号会原样输出
HelloController.class
@RestController
public class HelloController {
@RequestMapping("/hello")
public String Str(){
return "sfsf";
}
@Autowired //从容器中拿出Person对象
Person person;
@RequestMapping("/7777")
public Person person(){
return person;
}
}

在maven中导入依赖,这样我们在yaml中输入就会有提示
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
为了使maven打包更加便捷,我们可以让这个提示不打包
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
2.2欢迎页支持
-
静态资源路径下 index.html
-
controller能处理/index
添加浏览器图标
静态资源创建,favicon.ico
犹豫缓存问题,ctrl+f5清空就可以出来

浙公网安备 33010602011771号