springboot三层架构及常⽤注解
⼀、entiy
实体类,各种实体类型
常⽤注解
@Data 相当于get,set,tostring
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true) 链式写代码
@TableName(“数据库表”) 绑定数据库表
@TableField(“数据库中的名字”)
springboot结构⼆、controller
控制层
@requestMapping()url路径
@Controller 跳页⾯
@ResponseBody 返回数据
@RestController = @Controller + @ResponseBody
@Slf4j 开启⽇志注解
三、service
连接dao层进⾏操作,通常加@service注解
@service 注解⽤到serviceImpl层,使⽤之后可使⽤@Autowired,不会出现NullPoint异常
通常继承IService(相应的dao层,实体类)
四、dao
连接数据库层,写增删改查的⼀些⽅法,通常继承BaseMapper(实体类)
五、springboot启动类
@SpringBootApplication
@EnableTransactionManagement //事务注解
@MapperScan(“dao层路径”)
public class WhZwfwApplication {
}
@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan