spring boot 常用的注解整理

 

常用的注解整理

 

@SpringBootApplication   //启动类注解

@Data                //set/get/toString/equals

@NoArgsConstructor //无参构造

@AllArgsConstructor //全参构造

@Accessors(chain = true) //链式加载 重写set方法

@Configuration      //表示配置类

 

@Bean   //spring通过配置类实例化对象

@Service

@Controller

@ResponseBody

@RestController //返回JSON数据   =  @Controller +  @ResponseBody

 

@ConfigurationProperties(prefix = "jdbc")

@PathVariable

@RequestMapping("/getMsg")

 

@PropertySource("classpath:/properties/student.properties") //spring容器启动时加载指定的配置文件

@Mapper //mapper接口交给spring容器管理

@MapperScan("com.jt.mapper")  //添加在主启动类  添加mapper包扫描路径.实例化接口对象

 

@TableName //(value = "user")   //如果对象名称与表名一致则可以省略不写

@TableId(type = IdType.AUTO)    //标识主键

@TableField("name")        //如果名称一致(包含驼峰规则),注解可以省略

@SpringBootTest // 添加在测试类  动态启动了Spring容器

@Test    // 添加在测试类  单元测试5

 

@Value("${demo.name}")  

private String name;

/**

 * 表达式语法: spel表达式类似于el表达式 ${key}

 * 原理:从容器中动态获取名称为demo.name的值

 * name属性赋值

*/

 

@Autowired   //注入

 

//@Qualifier("userService")

//上述注解,为组合注解,作用按照指定的beanId注入

//@Resource(name="userService")

 

 

 

 

 

posted @ 2019-12-07 17:02  虎威  阅读(363)  评论(0)    收藏  举报