SpringBoot 注解,记录学习

一:SpringBoot程序启动

@SpringBootApplication 是一个“三体”结构,它是一个复合的Annotation,其中重要的三个Annotation

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SpringbootApplication {

   public static void main(String[] args) {
      SpringApplication.run(SpringbootApplication.class, args);
   }
}

等同于

@SpringBootApplication
public class SpringbootApplication {

   public static void main(String[] args) {
      SpringApplication.run(SpringbootApplication.class, args);
   }
}

@Configuration  它是javaConfig形式的Spring IOC 容器配置类使用的那个@Configuration,所以这个类标准了这个注解,就相当于是一个IOC容器配置类。

@EnableAutoConfiguration的功效:借助@Import的支持,收集和注册特定场景相关的bean的定义。

最关键的要属@Import(EnaBleAutoConfigurationImportSelector.class),借助EnaBleAutoConfigurationImportSelector

@EnableAutoConfiguration可以帮助SpringBoot将所有符合条件的@Configuration配置加载到当前的SpringBoot创建并使用的IOC容器.

二:controller,service,dao常用注解:

@Controller 注解在controller类上,标识其为一个可以接受http请求的控制器.通常配合@RequestMapping使用,代码如下:

@Controller
@RequestMapping("/sysuser") 
public class SysUserController extends BaseController {}

@RequestMapping(value = ''/xxx',method= RequestMethod.GET): 提供路由信息,负责URL到Controller具体的函数映射。 value :表示实际请求的URL地址,method :表示请求的方法: GET,POST,DELETE,PUT

@RestControlle  是@ResponseBody和@Controller的合集

@RestController
public class controller {

    @RequestMapping("say")
    public  String say(){
        return "hello springboot";
    }
}
@Service :用于修饰service 层的组件:

@Autowired:自动导入依赖的bean。

@Repository使用它可以确保Dao提供异常转译,这个注解修饰的Dao会被ComponetScan发现并配置.

@RequestParam 用在方法参数的前面。

三:JPA注解

@Entity表明这是一个实体类 。

@Column 表示字段名与数据库列名相同,name为表字段。

@id:表示为主键

@GeneratedValue(strategy = GenerationType.IDENTITY) :设置Id为自动增长

四:@Transaction 事务注解:可以用在接口,接口方法,类以及类方法上,当用在类上时,该类的所有public方法都具有事务属性。

猜你喜欢

转载自blog.csdn.net/qq_32722783/article/details/80838964