手记

SpringBoot 2.1.1.RELEASE 集成JPA


SpringBoot 2.1.1.RELEASE 集成JPA

参考:

http://www.qchcloud.cn/system/article/show/69

SpringBoot 2.1.1.RELEASE 集成JPA

依赖:

org.springframework.boot spring-boot-starter-data-jpa 1 2 3 4 5 编程: /** * 部门对象 sys_dept * */ @Entity @Table(name="app_dept") public class Dept extends BaseEntity { private static final long serialVersionUID = 1L; /** 部门ID */ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) // 设置主键自增 @Column(name = "dept_id") private Long deptId; /** 部门名称 */ @Column(name = "dept_name") private String deptName; public Long getDeptId() { return deptId; } public void setDeptId(Long deptId) { this.deptId = deptId; } public String getDeptName() { return deptName; } public void setDeptName(String deptName) { this.deptName = deptName; } } public interface DeptRepository extends JpaRepository { } public interface IDeptService { Dept findById(Long id); List findAll(); Dept save(Dept dept); void delete(Long id); Page findAll(Pageable pageable); } @Service public class DeptServiceImpl implements IDeptService { @Resource private DeptRepository deptRepository; @Override public Dept findById(Long id) { return deptRepository.getOne(id); } @Override public List findAll() { return deptRepository.findAll(); } @Override public Dept save(Dept dept) { return deptRepository.save(dept); } @Override public void delete(Long id) { deptRepository.deleteById(id); } @Override public Page findAll(Pageable pageable) { return deptRepository.findAll(pageable); } } 测试: @Test public void RepositoryTest(){ Dept dept=new Dept(); dept.setDeptName("研发中心"); deptService.save(dept); }

©著作权归作者所有:来自51CTO博客作者qchcloud的原创作品,如需转载,请注明出处,否则将追究法律责任


0人推荐
随时随地看视频
慕课网APP