目录
@EnableTransactionManagement和@Transactional
@Service、@Component、@Repository、@Controller
@Configuration
用于定义配置类,可替换xml配置文件
@MapperScan
指定要扫描的Mapper类的包的路径
@Value
获取*.porperties文件的内容,
@Value("${*.porperties文件中变量名}")
@Bean
是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里。添加的bean的id为方法名,可指定name。
@Autowired
对类成员变量、方法及构造函数进行标注,完成自动装配的工作。
@Qualifier
限定描述符除了能根据名字进行注入,更能进行更细粒度的控制如何选择候选者。
@EnableTransactionManagement和@Transactional
Spring Boot 使用事务非常简单,首先使用注解 @EnableTransactionManagement 开启事务支持后,然后在访问数据库的Service方法上添加注解 @Transactional 便可。
@Override
复写父类中已有的方法
@Service、@Component、@Repository、@Controller
如果一个类带了@Service注解,将自动注册到Spring容器,不需要再在applicationContext.xml文件定义bean了,类似的还包括@Component、@Repository、@Controller。
@RestController
@RestController注解相当于@Controller + @ResponseBody 合在一起的作用。
@ResponseBody
将controller的方法返回的对象通过适当的转换器转换为指定的格式之后,写入到response对象的body区,通常用来返回JSON数据或者是XML数据.
@RequestMapping
配置 Web 请求的映射
@ControllerAdvice
拦截异常并统一处理