zoukankan      html  css  js  c++  java
  • 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"):指定实体的位置

     
     
  • 相关阅读:
    MyBatis学习 之 三、动态SQL语句
    MyBatis学习 之 三、动态SQL语句
    MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
    MyBatis学习 之 二、SQL语句映射文件(2)增删改查、参数、缓存
    Spring3 MVC使用@ResponseBody的乱码问题及解决办法
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/yifanSJ/p/9389909.html
Copyright © 2011-2022 走看看