文章

SSM/SSH 框架常用注解(整合版)

SSM/SSH 框架常用注解(整合版)

本文整合了 SSM、SSH框架中注解ssm框架中注解的含义小结

1. Spring 组件注解

  • @Component:通用组件
  • @Controller:控制层
  • @Service:业务层
  • @Repository:数据访问层

组件扫描入口:

1
<context:component-scan base-package="org.example"/>

2. 依赖注入相关

  • @Autowired:按类型注入
  • @Qualifier:按名称细化匹配
  • @Resource:常用于按名称注入
  • @Value:读取配置值

3. Bean 作用域

  • singleton:单例(默认)
  • prototype:每次获取创建新对象
  • request:一次 HTTP 请求内有效
  • session:一次 HTTP 会话内有效

4. Spring MVC 常用注解

  • @RequestMapping
  • @RequestParam
  • @PathVariable
  • @CookieValue
  • @SessionAttributes
  • @ModelAttribute
  • @ResponseBody

5. AOP 常用注解

  • @Aspect
  • @Pointcut
  • @Before
  • @After
  • @AfterReturning
  • @AfterThrowing

6. Hibernate/JPA 常用注解

  • @Entity
  • @Table
  • @Id
  • @GeneratedValue
  • @Column
  • @OneToOne
  • @OneToMany
  • @JoinColumn

7. MyBatis 常用注解

  • @Param:为参数命名,避免多参数映射歧义。

相关阅读

本文由作者按照 CC BY 4.0 进行授权