Spring Boot 学习(一) 注意事项

2021-09-06 10:12

阅读:636

标签:autowire   span   config   can   div   system   tap   关于   property   编写引导类注意要标明注解 @SpringBootApplication SpringApplication.run(BootWeb01Application.class, args); 再编写main方法的时候使用run方法 起步依赖spring-boot-starter-parent 父工程,主要定义了一些版本的信息spring-boot-starter-web 用于web开发   package com.sp; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; @SpringBootApplication @ServletComponentScan(basePackages = "com.sp") //可以自动将写的servlet扫描进去 配置扫描的包 @MapperScan("com.sp.mapper") public class BootWeb01Application { public static void main(String[] args) { SpringApplication.run(BootWeb01Application.class, args); } }     关于yaml的配置 对象  person: name: xiaoming person: {name: xiaoming}   数组 address: - beijing - shanghai address: [beijing,shanghai]   纯量:单个,不可再分 msg1: ‘hello \n word‘ #单引忽略转义 msg1: "hello \n word" #双引不忽略转义   读取配置内容:三种方式 @Value @Value("${name}") //对象的话就用 . 属性的方式 eg:person.age public String name ; @Value("${person.age}") ... @Value("${address[0]}") //数组写法 ...   Environment 采用自动注入的方式 @Autowired private Environment env; public void hello() { System.out.println(env.getProperty("name")); System.out.println(env.getProperty("address[0]")); }   @ConfigurationProperties(prefix = "这里加上z主值的名字")   : 可以使配置的内容与对象进行一个映射 采用依赖注入的方式注意要满足与yaml文件下的对应内容   在mybatis中配置,配置POJO类的别名,可以在yaml中添加: mybatis: type-aliases-package: 包的名字  Spring Boot 学习(一) 注意事项标签:autowire   span   config   can   div   system   tap   关于   property   原文地址:https://www.cnblogs.com/YuyuFishSmile/p/14964893.html


评论


亲,登录后才可以留言!