Spring注解记录

1.@Qualifier: 这个注解与@Autowired组合使用,当注入的对象是个接口,有多个实现类时,你可以用@Qualifier("bean的名称")来指定到底是哪个对象

2.@PathVariable:用来接收get/post传来的参数

@GetMapping("/user/{id}")
public void findPet(@PathVariable Integer id) {}

3.@PathVariable与@RequestParam的区别:

使用@RequestParam时,URL为:http://host:port/path?参数名=参数值

使用@PathVariable时,URL为的:http://host:port/path/参数值

区别就是参数跟在?后面用@RequestParam,参数直接是反斜杠,就用@PathVariable

4.@Async 方法开启异步调用

5.@Alias("") 这个是mybatis的注解,注解在实体类上,这样在写sql时,resulType可以直接写引号里的别名了

6.@Component与@Bean的区别:

  • @Component注解表明一个类会作为组件类,并告知Spring要为这个类创建bean。
  • @Bean注解告诉Spring这个方法将会返回一个对象,这个对象要注册为Spring应用上下文中的bean。通常方法体中包含了最终产生bean实例的逻辑。

两者的目的是一样的,都是注册bean到Spring容器中。



 

猜你喜欢

转载自blog.csdn.net/reee112/article/details/85762646