springboot的优点就不多做介绍了,只来谈谈springboot常用的注解,希望对朋友们有帮助。
1.@SpringBootApplication
springboot的核心注解,用来开启Springboot的各项功能相当于@Configuration+@ComponentScan+EnableAutoConfiguration
2.@MapperScan(basePackages="mapper类所在的包")
指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
3.@ComponentScan
指明需要扫描的包默认扫描所在包及子包
4.@ExceptionHandler 表示异常拦截
5.@ControllerAdvice
controller 的一个辅助类,最常用的就是作为全局异常处理的切面类可以指定扫描范围,约定了几种可行的返回值,如果是直接返回 model 类的话,需要使用@ResponseBody 进行 json 转换
6.@Value
用来获取自定义的属性值
7.@ConfigurationProperties(prefix="前缀")
作用在类上,用来获取拥有该前缀的自定义的属性
8.@PropertySource("classpath:xxx.properties")
作用在类上,项目启动加载该配置文件
9.@Configuration
声明当前类是一个配置类,相当于Spring配置的xml文件
10.@EnableTransactionManagement
开启事务的注解配置
11.@RestController
相当于@Controller+@ResponseBody
ssm常用注解:
@Controller 作用于controller层,将其声明为spring的Bean
@Service : 在业务逻辑层(service层)使用
@Repository : 在数据访问层(dao层)使用.
@Component : 组件,没有明确的角色
@Autowired 自动装配 spring的注解
@Resource 自动注入 是j2ee的,但是spring支持
@RequestMapping 作用于方法或类上,设置访问的url
@ResponseBody 返回json数据
@RequestBody 接收前台的json数据
@PathVariable 接收路径参数如:/order/update/1
@PathVariable("id") Long id
@requestParam 接收路径中?后的参数
@RequestParam(value = "id", required = false, defaultValue = "0") Long id
@RunWith(SpringJUnit4ClassRunner.class) 单元测试
@ContextConfiguration 加载spring的配置文件
@Transactional 事务注解
总结多有不足,欢迎留言指正。。。。。