spring常用注解

深藏阁楼爱情的钟 2022-02-24 10:26 438阅读 0赞

java内置注解

@Override 覆盖父类方法

@Deprecated 表示方法已过期,不推荐使用

@Suppvisewarning 忽略警告

spring注解

@Component(“指定bean的id”)

作用:把对象加入IOC容器,难以归类时使用,不建议使用

@Controller一般在控制层使用

@Service一般在业务层使用

@Repository一般在数据持久层使用

以上注解作用在类上,相当于:

@Resource(name=””)

默认先按名字装配,若没有则按类型装配,J2EE提供

相当于:

@Autowired

按类型自动装配,spring提供

@Qualifier

一般作为@Autowired修饰使用

以上作用用于处理对象依赖关系,建议使用@Resource减少与spring之间的耦合

@RequestMapping(value= ‘xx’, method=XX)

表名该方法处理URL和请求类型

@GetMapping() 相当于@RequestMapping(method = RequestMethod.GET)

@PostMapping() 相当于@RequestMapping(method = RequestMethod.POST)

@PathVariable 绑定参数,如@RequestMapping(“{url}“)

@RestController 相当于@Controller与@ResponseBody的结合体

@ComponentScan({ “包名”})

作用:扫描包下的类

相当于:

@PostConstruct

相当于init-method,当Bean初始化时执行。

@PreDestroy

相当于destory-method,当Bean销毁时执行。

@Transactional 事务声明

@Configuration

表明是一个配置类

@Test

junit 表明为测试方法

@Id

声明属性为主键

@Column(name= “xxx”)

声明属性在数据库中的名称

https://www.cnblogs.com/yanze/p/9481915.html

发表评论

表情:
评论列表 (有 0 条评论,438人围观)

还没有评论,来说两句吧...

相关阅读