继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

SpringBoot 2.1.1.RELEASE 集成JPA

holdtom
关注TA
已关注
手记 1703
粉丝 240
获赞 991


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的原创作品,如需转载,请注明出处,否则将追究法律责任


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP