码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot 2.1.1.RELEASE 集成JPA

时间:2018-12-12 23:47:21      阅读:377      评论:0      收藏:0      [点我收藏+]

标签:dal   cti   delete   jpa   page   http   follow   override   osi   

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

标签:dal   cti   delete   jpa   page   http   follow   override   osi   

原文地址:http://blog.51cto.com/14042154/2329728

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!