1. 程式人生 > >SpringBoot 2.1.1.RELEASE 集成JPA

SpringBoot 2.1.1.RELEASE 集成JPA

oid inter pri ndb pts str page cti table

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); }

SpringBoot 2.1.1.RELEASE 集成JPA