SpringBoot注解

在Main()方法启动类上使用
@SpringBootApplication:标注它是一个Spring Boot应用,等价于(默认属性)@Configuration + @EnableAutoConfiguration + @ComponentScan。
1. @Configuration:标识这个类可以是Spring IoC容器。它和@Bean可以用来替代xml配置文件。@Bean注解告诉Spring注解方法将返回一个对象,该对象应被注册为在Spring应用程序上下文中。
2. @EnableAutoConfiguration:能够自动配置spring的上下文,试图猜测和配置你想要的bean类,Spring Boot会自动根据你jar包的依赖来自动配置项目。例如当你项目下面有HSQLDB的依赖时,Spring Boot会创建默认的内存数据库的数据源DataSource。
3. @ComponentScan:会自动扫描指定包下的全部标有@Component的类,并注册成bean,当然包括@Component下的子注解@Service,@Repository,@Controller。
在配置类上使用
@Order(Ordered.HIGHEST_PRECEDENCE) 控制配置类的加载顺序,数值越小越先加载
@EnableTransactionManagement(proxyTargetClass = true) 开启事务注解,在Service方法上增加@Transactional
@EnableJpaRepositories(basePackages = "com.yweb.dao") 让spring在加载的时候找到我们自定义的BaseRepository
@EntityScan(basePackages = "com.yweb.entity") 扫描Entity实体类
 
@RestController 标注这个程序还是一个控制器

 
@EnableTransactionManagement:开启注解事务管理,等同于xml配置文件中的 <tx:annotation-driven />
@ComponentScan(basePackages = "com.yweb"):可注解掉,默认扫描当前包下
@SpringBootApplication
@RestController
@RequestMapping("/")

@Entity
@Table(name = "deparment")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ManyToOne
@JoinColumn(name = "did"):注释本表中指向另一个表的外键
@JsonBackReference:防止关系对象的递归访问
@ManyToMany(cascade = {}, fetch = FetchType.EAGER)
@JoinTable(name = "user_role",joinColumns = {@JoinColumn(name="user_id")},inverseJoinColumns = {@JoinColumn(name = "roles_id")}):多对多的中间表信息

@Mapper:Mapper接口类上,便于springboot扫描

@Order(Ordered.HIGHEST_PRECEDENCE):控制配置类的加载顺序,数值越小越先加载
@Configuration:标识这个类可以是Spring IoC容器。它和@Bean可以用来替代xml配置文件。@Bean注解告诉Spring注解方法将返回一个对象,该对象应被注册为在Spring应用程序上下文中。
@Bean
@EnableTransactionManagement(proxyTargetClass = true):开启JPA事务注解,在Service方法上增加@Transactional
@EnableJpaRepositories(basePackages = "com.yweb.dao"):让spring在加载的时候找到我们自定义的BaseRepository
@EntityScan(basePackages = "com.yweb.entity"):指定实体的位置

 
 

转载于:https://www.cnblogs.com/yifanSJ/p/9389909.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值