1.entity下面的实体类映射数据库的一张表数据库的
如下
boy表:
映射boy表的数据库:
@Data @Entity(name = "t_test_boy") @Table(appliesTo ="t_test_boy" ,comment = "男孩") @EntityListeners(AuditingEntityListener.class) public class TTestBoy extends BaseEntity { /** * 年龄 */ @Column(name="age", columnDefinition = "int(11) COMMENT '年龄'" ) private Long age; /** * 生日 */ @Column(name="birthday", columnDefinition = "varchar(12) COMMENT '生日'" ) private String birthday; /** * 是否有女朋友 */ @Column(name="has_girl_friend", columnDefinition = "tinyint(4) COMMENT '是否有女朋友'" ) private Integer hasGirlFriend; /** * 姓名 */ @Column(name="name", columnDefinition = "varchar(32) COMMENT '姓名'" ) private String name; }
注:继承的BaseEntity类是每个实体类必须继承的,里面提供了一些实体类的公共属性
如:
@MappedSuperclass @Data @JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"}) public abstract class BaseEntity implements Serializable { @Id @GeneratedValue private Long id; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") @CreationTimestamp @Column(name = "create_time", columnDefinition = "DATETIME COMMENT '创建时间/注册时间'", updatable = false) private Date createTime; @Column(name = "create_by", columnDefinition = "bigint COMMENT '创建人'", updatable = false) @CreatedBy private Long createBy; @UpdateTimestamp @Column(name = "modify_time", columnDefinition = "DATETIME COMMENT '最后更新时间'") private Date modifyTime; @LastModifiedBy @Column(name = "modify_by", columnDefinition = "bigint COMMENT '最后更新人'") private Long modifyBy; }
==================================================================================================================================================
2.controller层的控制类
实现controller来查看来查看:
继承了BasController类
过滤器(通过过滤属性,来以此达到查的功能),增,删,改
@RestController @RequestMapping("/test/boy") public class TTestBoyController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private TTestBoyService tTestBoyService; @RequestMapping(value = "/list",method = RequestMethod.GET) @RequiresPermissions(value = "/test/boy") public Object list(@RequestParam(required = false) Long id){ Page<TTestBoy> page = new PageFactory<TTestBoy>().defaultPage(); page.addFilter("id",id); page = tTestBoyService.queryPage(page); return Rets.success(page); } @RequestMapping(method = RequestMethod.POST) @BussinessLog(value = "新增男孩", key = "name") @RequiresPermissions(value = "/test/boy/add") public Object add(@ModelAttribute TTestBoy tTestBoy){ tTestBoyService.insert(tTestBoy); return Rets.success(); } @RequestMapping(method = RequestMethod.PUT) @BussinessLog(value = "更新男孩", key = "name") @RequiresPermissions(value = "/test/boy/update") public Object update(@ModelAttribute TTestBoy tTestBoy){ tTestBoyService.update(tTestBoy); return Rets.success(); } @RequestMapping(method = RequestMethod.DELETE) @BussinessLog(value = "删除男孩", key = "id") @RequiresPermissions(value = "/test/boy/delete") public Object remove(Long id){ if (id == null) { throw new ApplicationException(BizExceptionEnum.REQUEST_NULL); } tTestBoyService.delete(id); return Rets.success(); } }
==================================================================================================================================================
3.业务层
通过业务层可以实现不同模块的不同业务
所以业务层是核心
@Service public class TTestBoyService extends BaseService<TTestBoy,Long,TTestBoyRepository> { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private TTestBoyRepository tTestBoyRepository; }
==================================================================================================================================================
4.dao层
用来存储各种增删改查的jdbc
public interface TTestBoyRepository extends BaseRepository<TTestBoy,Long>{ }