ssm框架常用注解整理

SpringBoot

- Controller:
@RestController
* 启动类:
@MapperScan("edu.cque.mapper")
@SpringBootApplication
+ 其他情况:
@Autowired
@component
@Bean
@Bean@Autowired 做了两件完全不同的事情:
@Bean 告诉 Spring:“这是这个类的一个实例,请保留它,并在我请求时将它还给我”。
@Autowired 说:“请给我一个这个类的实例,例如,一个我之前用@Bean注释创建的实例”。

SpringMvc专用注解

- 启动类:
@SpringBootApplication//启动类SpringMVC专用注解
				//spring提供的,表示自己是一个启动类,用来启动服务器
- Controller:
	- 类上:
@RestController
@RequestMapping("car")
@CrossOrigin  //放行js的访问请求
@PropertySource(value = "classpath:/mysql.properties",encoding = "utf-8")//读取/引入resource下的properties和yml配置文件
@Value("${mysql.user}")//和propertySource配置使用,根据配置文件里面的key对字段进行依赖注入

	- 方法上: 
	@RequestMapping("test1")
	- 字段上:
@Autowired
@Value("${mysql.user}")
	参数前:
@Param(“uId”)
	restFull类型参数解析:
@path Variable无参则默认绑定后面的变量名以适配请求路径参数名,
			如果指定参数,则按指定参数名去匹配请求路径参数名.

Spring专用注解

- 启动类:
@Configuration
@ComponentScan("edu.cque.day05")
@EnableAspectJAutoProxy //开启 Aspect 生成代理对象
- 代理类:
	 - 类名上:
@Aspect
@Component
 	- 方法上:
//切点表达式
@Pointcut("execution(* edu.cque.day05.*.add(..))")
//通知类型
@Before("pointcut()")
@After("pointcut()")
@AfterReturning("pointcut()")
@AfterThrowing("pointcut()")
@Around("pointcut()")

Mybatis专用注解

- 实体类:
@Accessors(chain = true) //开启链式加载
@Data
@NoArgsConstructor//无参构造
@AllArgsConstructor//全参构造

自己的学习笔记,后续持续更新中…


  • 课外拓展:
    @MapperScan
    • 1.首先了解@Mapper
      在持久层的接口上添加@Mapper注解,编译后会生成相应的接口实现类,但由于要在每个接口上都进行配置,所以产生了@MapperScan。
    • 2.@MapperScan
      指定要编译成接口实现类的包路径,在编译完成后这个包下的所有接口都会生成相应的接口实现类。
  • @ComponentScan
    1.会自动扫描包路径下的@Controller、@Service、@Repository、@Component类,符合扫描规则的类会装配到spring容器中。
    2.@MapperScan和@ComponentScan可以同时使用
    如果@MapperScan和@ComponentScan扫描的是同一路径会产生错误,
    原文链接:https://blog.csdn.net/weixin_45948234/article/details/110954215
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

华哥啊.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值