SpringBoot 2.1.1.RELEASE 集成JPA
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
}!-->以上是关于SpringBoot 2.1.1.RELEASE 集成JPA的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot 2.1.1.RELEASE 集成MyBatis
SpringBoot 2.1.1.RELEASE集成devtools
SpringBoot 2.1.1.RELEASE 集成quartz
SpringBoot 2.1.1.RELEASE 集成Email
SpringBoot 2.1.1.RELEASE 集成log4j2
SpringBoot-整合Swagger2