文章目录
- 1.@PostConstruct说明
- 2.@PreDestroy说明
- 3. @ResponseBody说明
- 4. @Transactional(timeout=30)
- 5.@ModelAttribute("model")
- 6.@Mapper
- 7.@Requestmapping
- 8.PathVariable相当于占位符的作用
- 9.@Configuration
- 10.@EnableAutoConfiguration
- 11@Resource@Autowired
- 11. @GetMapping("/userrole/{storeid}")
- 12.@RequestBody
- 13. @SuppressWarnings("Duplicates")
- 14. @RequestMapping
- 15. @GetMapping
- 16.@RestController
- 17.@SpringBootTest
- 18.@component
- 19. @ConfigurationProperties
- 20.@Validated
1.@PostConstruct说明
被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器调用一次,类似于Serclet的inti()方法。被@PostConstruct修饰的方法会在构造函数之后,init()方法之前运行。
2.@PreDestroy说明
被@PreDestroy修饰的方法会在服务器卸载Servlet的时候运行,并且只会被服务器调用一次,类似于Servlet的destroy()方法。被@PreDestroy修饰的方法会在destroy()方法之后运行,在Servlet被彻底卸载之前。
3. @ResponseBody说明
将java对象转为json格式的数据
4. @Transactional(timeout=30)
事务的注解,默认过期时间是30秒
5.@ModelAttribute(“model”)
往前台传数据,可以传对象,可以传List,通过el表达式 ${}可以获取到,
类似于request.setAttribute(“sts”,sts)效果一样。
6.@Mapper
@Mapper注解,目的就是为了不再写mapper映射文件
7.@Requestmapping
相对于类定义处的URL
8.PathVariable相当于占位符的作用
9.@Configuration
注解类标识这个类可以使用Spring IoC容器作为bean定义的来源。@Bean注解告诉Spring,一个带有@Bean的注解方法将返回一个对象,该对象应该被注册为在Spring应用程序上下文中的bean。
10.@EnableAutoConfiguration
能够自动配置spring的上下文,试图猜测和配置你想要的bean类,通常会自动根据你的类路径和你的bean定义自动配置。
11@Resource@Autowired
都可以用来装配bean,都可以用于字段或setter方法。
@Autowired默认按类型装配,默认情况下必须要求依赖对象必须存在,如果要允许null值,可以设置它的required属性为false。
@Resource默认按名称装配,当找不到与名称匹配的bean时才按照类型进行装配。名称可以通过name属性指定,如果没有指定name属性,当注解写在字段上时,默认取字段名,当注解写在setter方法上时,默认取属性名进行装配。
注意:如果name属性一旦指定,就只会按照名称进行装配。
@Autowire和@Qualifier配合使用效果和@Resource一样:
@Autowired(required = false) @Qualifier(“example”)
private Example example;
@Resource(name = “example”)
private Example example;
11. @GetMapping("/userrole/{storeid}")
@PathVariable @PathVariable(name = “storeid”)
12.@RequestBody
直接返回到浏览器,会根据json字符串中的key来匹配对应实体类的属性
@RequestBody Student student
13. @SuppressWarnings(“Duplicates”)
去掉警告信息
14. @RequestMapping
@RequestMapping(value = “/get/{id}”, method = RequestMethod.GET)新方法可以简化为:@GetMapping("/get/{id}")
15. @GetMapping
@GetMapping,@PostMapping,@DelectMapping
16.@RestController
由 @ResponsBody 和 Controller 组成
17.@SpringBootTest
SpringBoot 单元测试注解
18.@component
把普通pojo实例化到spring容器中,相当于配置文件中的
泛指各种组件,就是说当我们的类不属于各种归类的时候(不属于@Controller、@Services等的时候),我们就可以使用@Component来标注这个类
19. @ConfigurationProperties
告诉SpringBoot将本类中的所有属性和配置文件中相关的配置进行绑定;
属性: prefix = “yml中映射文件名”:配置文件中哪个下面的所有属性进行一一映射
使用方法,例: @ConfigurationProperties(prefix = “person”)
20.@Validated
用于JSR303数据校验
未完待续,一直更新.