spring data jpa 之 通用接口
园主这一阵子接到一个需求,就是将spring data jpa再进行封装,实现通过调用一个baseRepository,来实现每个类的增删改查操作,结合spring data jpa 原有的便捷操作,实现快捷开发,话不多说,上代码!
1 首先编写通用接口
package com.hhsj.repository; import com.hhsj.base.Params;
import com.hhsj.base.Result;
import org.springframework.data.jpa.repository.JpaRepository; import java.util.LinkedHashMap;
import java.util.List; public interface baseRepository<T ,ID>{ /**
* 保存数据对象
* @param entity
* @return
*/
Boolean save(T entity);
/**
* 根据id查询
* @param clazz
* @param id
* @return
*/
T findByid(Class<T> clazz,ID id);
/**
* 根据表名,字段,参数查询,拼接sql语句
* @param clazz 表的class
* @param filed 字段名
* @param o 字段参数
* @return
*/
List<T> findByField(Class<T> clazz, String filed, Object o); /**
* 多个字段的查询
* @param clazz 表的class
* @param map 将你的字段传入map中
* @return
*/
List<T> findByMoreFiled(Class<T> clazz,LinkedHashMap<String,Object> map); /**
* 根据表的id删除数据
* @param entity
*/
Boolean delete(T entity);
/**
* 更新对象
* @param e
* @return
*/
Boolean update(T e ,ID id);
/**
* 根据条件查询总条数返回object类型
* @param clazz 表的class
* @param map 传入参数放入map中
* @return
*/
Integer findCount(Class<T> clazz, LinkedHashMap<String,Object> map); /**
* 通过传入自定义参数查询
* @param clazz
* @param params
* @return
*/
List<T> findByParams(Class<T> clazz , Params params); /**
* 根据id删除
* @param clazz
* @param id
* @return
*/
Boolean deleteById(Class<T> clazz, ID id); /**
* 通过id集合批量删除
* @param clazz
* @param ids
* @return
*/
Boolean deleteByIds(Class<T> clazz , List<ID> ids);
}
BaseRepository
2 通用接口的实现类
package com.hhsj.repository; import com.hhsj.base.BeanUtils;
import com.hhsj.base.Params;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.transaction.Transactional;
import java.lang.reflect.Field;
import java.util.*; @Repository
public class BaseRepositoryImpl<T,ID> implements baseRepository<T,ID>{ @PersistenceContext
private EntityManager entityManager; @Override
@Transactional
public Boolean save(T entity){
boolean flag = false;
try {
entityManager.persist(entity);
flag = true;
}catch (Exception e){
System.out.println("---------------保存出错---------------");
e.printStackTrace();
}
return flag;
} @Override
public T findByid(Class<T> clazz,ID id) {
T t = null;
try {
t = entityManager.find(clazz, id);
} catch (Exception e) {
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return t;
} @Override
public List<T> findByField(Class<T> clazz, String filed, Object value ) {
String tablename = clazz.getName();
List<T> list = new ArrayList<>();
try {
String sql="from "+tablename+" u WHERE u."+filed+"=?1";
Query query=entityManager.createQuery(sql);
query.setParameter(1,value);
list= query.getResultList();
entityManager.close();
}catch (Exception e){
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return list;
} @Override
@Transactional
public Boolean deleteById(Class<T> clazz, ID id) {
Boolean flag = false;
try {
String tableName = clazz.getName();
String sql = "delete from "+tableName+" u WHERE u.id = ?1";
Query query=entityManager.createQuery(sql);
query.setParameter(1,id);
int i = query.executeUpdate();
if(i != 0){
flag = true;
}
entityManager.close();
} catch (Exception e) {
e.printStackTrace();
} return flag;
} @Override
@Transactional
public Boolean deleteByIds(Class<T> clazz, List<ID> ids) {
boolean flag = false;
List<ID> param = new ArrayList<ID>();
int index = 1;
try {
String tableName = clazz.getName();
StringBuilder sql = new StringBuilder("delete from "+tableName+" u WHERE u.id in (");
if (ids != null && ids.size() != 0){
for (ID id : ids) {
sql.append("?").append(index).append(",");
param.add(id);
index ++ ;
}
}
sql.deleteCharAt(sql.length() - 1 );
sql.append(")");
Query query=entityManager.createQuery(sql.toString());
for (int x = 0;x < param.size();x++) {
query.setParameter(x+1,param.get(x));
}
int i = query.executeUpdate();
if (i != 0){
flag = true;
}
entityManager.close();
} catch (Exception e) {
e.printStackTrace();
}
return flag;
} @Override
public List<T> findByMoreFiled(Class<T> clazz,LinkedHashMap<String,Object> map) {
String tablename = clazz.getName();
List<T> listRe = new ArrayList<>();
try {
String sql="from "+tablename+" u WHERE ";
Set<String> set=null;
set=map.keySet();
List<String> list=new ArrayList<>(set);
List<Object> filedlist=new ArrayList<>();
int x = 1;
for (String filed:list){
sql+="u."+filed+"=?"+x+" and ";
filedlist.add(filed);
x++;
}
sql=sql.substring(0,sql.length()-4);
Query query=entityManager.createQuery(sql);
for (int i=0;i<filedlist.size();i++){
query.setParameter(i+1,map.get(filedlist.get(i)));
}
listRe= query.getResultList();
entityManager.close();
}catch (Exception e){
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return listRe;
} @Override
@Transactional
public Boolean update(T entity,ID id) {
boolean flag = false;
try {
Object o = entityManager.find(entity.getClass(), id);
BeanUtils.copyPropertiesExcludeNull(entity,o);
entityManager.merge(o);
flag = true;
} catch (Exception e) {
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return flag;
} @Override
@Transactional
public Boolean delete(T entity) { //entity通过设置id来删除相应数据
boolean flag=false;
try {
entityManager.remove(entityManager.merge(entity));
flag=true;
}catch (Exception e){
System.out.println("---------------删除出错---------------");
e.printStackTrace();
}
return flag;
} @Override
public Integer findCount(Class<T> clazz, LinkedHashMap<String, Object> map) {
String tablename = clazz.getName();
Query query= null;
Object count = 0;
try {
String sql="select count(u) from "+tablename+" u WHERE ";
Set<String> set=null;
set=map.keySet();
List<String> list=new ArrayList<>(set);
List<Object> filedlist=new ArrayList<>();
int x = 1;
for (String filed:list){
sql+="u."+filed+"=?"+ x +" and ";
x++;
filedlist.add(filed);
}
sql=sql.substring(0,sql.length()-4);
query = entityManager.createQuery(sql);
for (int i=0;i<filedlist.size();i++){
query.setParameter(i+1,map.get(filedlist.get(i)));
}
count = query.getSingleResult();
} catch (Exception e) {
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return Integer.parseInt(count.toString());
} @Override
public List<T> findByParams(Class<T> clazz, Params params) {
String tablename = clazz.getName();
List<T> listRe = new ArrayList<>();
//jpa运行时需要的参数
List param = new ArrayList();
try {
StringBuilder sql = new StringBuilder();
sql.append("from ").append(tablename).append(" u WHERE 1=1 ");
int index = 0;
//拼接sql,添加参数集合
index = concatSqlForObj(index,param, sql, params.getAnd(), params.getAndPara());
index = concatSqlForObj(index,param, sql, params.getOr(), params.getOrPara());
index = concatSqlForList(index,param, sql, params.getBetween(), params.getBetweenPara());
index = concatSqlForObj(index,param, sql, params.getLessThan(), params.getLessThanPara());
index = concatSqlForObj(index,param, sql, params.getMoreThan(), params.getMoreThanPara());
index = concatSqlForObj(index,param, sql, params.getLike(), params.getLikePara());
index = concatSqlForObj(index,param, sql, params.getNotLike(), params.getNotLikePara());
index = concatSqlForObj(index,param, sql, params.getOrderBy(), params.getOrderByPara());
index = concatSqlForObj(index,param, sql, params.getNot(), params.getNotPara()); index = concatSqlForList(index,param, sql, params.getIn(), params.getInPara());
index = concatSqlForList(index,param, sql, params.getNotIn(), params.getNotInPara()); Query query=entityManager.createQuery(sql.toString());
//limit
if (params.getLimitPara() != null){
List list = params.getLimitPara().get("limit");
query.setFirstResult((Integer) list.get(0));
query.setMaxResults((Integer) list.get(1));
}
for (int i=0;i<param.size();i++){
query.setParameter(i+1,param.get(i));
}
listRe= query.getResultList();
entityManager.close();
}catch (Exception e){
System.out.println("---------------查询出错---------------");
e.printStackTrace();
}
return listRe;
} public static int concatSqlForObj(int index,List param ,StringBuilder sql , List<String> symbols , LinkedHashMap<String , Object> params){
//拼接sql时需要的参数索引
int index1 = index;
//取list中的键值对是需要的索引
int x = 0;
if (symbols != null && symbols.size() != 0){
for (String symbol: symbols) {
//通过转换list获取键值对
List<Map.Entry<String, Object>> indexedList = new ArrayList<Map.Entry<String, Object>>(params.entrySet());
Map.Entry<String, Object> entry = indexedList.get(x);
String key = entry.getKey();
Object value = entry.getValue(); index1 ++ ;
x++; if (symbol.equals("or")){
sql.append(" or u.").append(key).append("=?").append(index1);
}else if(symbol.equals("<")){
sql.append(" and u.").append(key).append("<?").append(index1);
}else if(symbol.equals(">")){
sql.append(" and u.").append(key).append(">?").append(index1);
}else if(symbol.equals("like")){
sql.append(" and u.").append(key).append(" like ?").append(index1);
}else if(symbol.equals("notlike")){
sql.append(" and u.").append(key).append(" not like ?").append(index1);
}else if(symbol.equals("!=")){
sql.append(" and u.").append(key).append(" != ?").append(index1);
}
else if(symbol.equals("orderby")){
//val的值可取asc 和 desc
sql.append(" ORDER BY ").append(key).append(" ").append(value.toString());
return index1;
}
else {
sql.append(" and u."+key + symbol+"?" + index1);
}
param.add(value);
}
}
return index1;
} public static int concatSqlForList(int index,List param ,StringBuilder sql , List<String> symbols , LinkedHashMap<String , List> params){
//拼接sql时需要的参数索引
int index1 = index;
//取list中的键值对是需要的索引
int x = 0;
if (symbols != null && symbols.size() != 0){
for (String symbol: symbols) {
//通过转换list获取键值对
List<Map.Entry<String, List>> indexedList = new ArrayList<Map.Entry<String, List>>(params.entrySet());
Map.Entry<String, List> entry = indexedList.get(x);
String key = entry.getKey();
List value = entry.getValue(); index1 ++ ;
x++; if(symbol.equals("between")){
sql.append(" and u.").append(key).append(" between ?").append(index1).append(" and ?").append(index1 + 1);
index1 ++;
}else if (symbol.equals("in") || symbol.equals("notin")){
sql.append(" and u.").append(key);
if (symbol.equals("in")){
sql.append(" in (?");
}else {
sql.append(" not in (?");
}
sql.append(index1);
param.add(value.get(0));
for (int i = 1 ; i < value.size() ; i++){
index1 ++;
sql.append(",?").append(index1);
param.add(value.get(i));
}
sql.append(")");
return index1;
}
param.add(value.get(0));
param.add(value.get(1));
}
}
return index1;
}
}
BaseRepositoryImpl
3 多条件查询的参数类
package com.hhsj.base; import lombok.Data; import java.util.ArrayList;
import java.util.List;
import java.util.LinkedHashMap; /**
* 自定义参数
*/
@Data
public class Params { private final List<String> and;
private final LinkedHashMap<String ,Object> andPara; private final List<String> or;
private final LinkedHashMap<String ,Object> orPara; private final List<String> between;
private final LinkedHashMap<String ,List> betweenPara; private final List<String> lessThan;
private final LinkedHashMap<String ,Object> lessThanPara; private final List<String> moreThan;
private final LinkedHashMap<String ,Object> moreThanPara; /* private final List<String> isNull;
private final LinkedHashMap<String ,Object> isNullPara; private final List<String> isNotNull;
private final LinkedHashMap<String ,Object> isNotNullPara;*/ private final List<String> like;
private final LinkedHashMap<String ,Object> likePara; private final List<String> notLike;
private final LinkedHashMap<String ,Object> notLikePara; private final List<String> orderBy;
private final LinkedHashMap<String ,Object> orderByPara; private final List<String> not;
private final LinkedHashMap<String ,Object> notPara; private final List<String> in;
private final LinkedHashMap<String ,List> inPara; private final List<String> notIn;
private final LinkedHashMap<String ,List> notInPara; private final List<String> limit;
private final LinkedHashMap<String ,List> limitPara; private Params(Bulider bulider){
this.and = bulider.and;
this.andPara = bulider.andPara;
this.or = bulider.or;
this.orPara = bulider.orPara;
this.between = bulider.between;
this.betweenPara = bulider.betweenPara;
this.lessThan = bulider.lessThan;
this.lessThanPara = bulider.lessThanPara;
this.moreThan = bulider.moreThan;
this.moreThanPara = bulider.moreThanPara;
/*this.isNull = bulider.isNull;
this.isNullPara = bulider.isNullPara;
this.isNotNull = bulider.isNotNull;
this.isNotNullPara = bulider.isNotNullPara;*/
this.like = bulider.like;
this.likePara = bulider.likePara;
this.notLike = bulider.notLike;
this.notLikePara = bulider.notLikePara;
this.orderBy = bulider.orderBy;
this.orderByPara = bulider.orderByPara;
this.not = bulider.not;
this.notPara = bulider.notPara;
this.in = bulider.in;
this.inPara = bulider.inPara;
this.notIn = bulider.notIn;
this.notInPara = bulider.notInPara;
this.limit = bulider.limit;
this.limitPara = bulider.limitPara;
} public static Params.Bulider builder() {
return new Params.Bulider();
} public static class Bulider{
private List<String> and;
private LinkedHashMap<String ,Object> andPara; private List<String> or;
private LinkedHashMap<String ,Object> orPara; private List<String> between;
private LinkedHashMap<String ,List> betweenPara; private List<String> lessThan;
private LinkedHashMap<String ,Object> lessThanPara; private List<String> moreThan;
private LinkedHashMap<String ,Object> moreThanPara; /* private List<String> isNull;
private LinkedHashMap<String ,Object> isNullPara; private List<String> isNotNull;
private LinkedHashMap<String ,Object> isNotNullPara;*/ private List<String> like;
private LinkedHashMap<String ,Object> likePara; private List<String> notLike;
private LinkedHashMap<String ,Object> notLikePara; private List<String> orderBy;
private LinkedHashMap<String ,Object> orderByPara; private List<String> not;
private LinkedHashMap<String ,Object> notPara; private List<String> in;
private LinkedHashMap<String ,List> inPara; private List<String> notIn;
private LinkedHashMap<String ,List> notInPara; private List<String> limit;
private LinkedHashMap<String ,List> limitPara; public Bulider Euqal(String key , Object value){
this.and = new ArrayList<>();
this.andPara = new LinkedHashMap<>();
this.and.add("=");
this.andPara.put(key,value);
return this;
} public Bulider Or(String key , Object value){
this.or = new ArrayList<>();
this.orPara = new LinkedHashMap<>();
this.or.add("or");
this.orPara.put(key,value);
return this;
} public Bulider Between(String key , Object value1 , Object value2){
this.between = new ArrayList<>();
this.betweenPara = new LinkedHashMap<>();
List value = new ArrayList();
value.add(value1);
value.add(value2);
this.between.add("between");
this.betweenPara.put(key,value);
return this;
} public Bulider LessThan(String key , Object value){
this.lessThan = new ArrayList<>();
this.lessThanPara = new LinkedHashMap<>();
this.lessThan.add("<");
this.lessThanPara.put(key,value);
return this;
} public Bulider MoreThan(String key , Object value){
this.moreThan = new ArrayList<>();
this.moreThanPara = new LinkedHashMap<>();
this.moreThan.add(">");
this.moreThanPara.put(key,value);
return this;
} /*public Bulider IsNull(String key , Object value){
this.isNull = new ArrayList<>();
this.isNullPara = new LinkedHashMap<>();
this.isNull.add("isnull");
this.isNullPara.put(key,value);
return this;
} public Bulider IsNotNull(String key , Object value){
this.isNotNull = new ArrayList<>();
this.isNotNullPara = new LinkedHashMap<>();
this.isNotNull.add("isnotnull");
this.isNotNullPara.put(key,value);
return this;
}*/ public Bulider Like(String key , Object value){
this.like = new ArrayList<>();
this.likePara = new LinkedHashMap<>();
this.like.add("like");
this.likePara.put(key,value);
return this;
} public Bulider NotLike(String key , Object value){
this.notLike = new ArrayList<>();
this.notLikePara = new LinkedHashMap<>();
this.notLike.add("notlike");
this.notLikePara.put(key,value);
return this;
} public Bulider OrderBy(String key , Object value){
this.orderBy = new ArrayList<>();
this.orderByPara = new LinkedHashMap<>();
this.orderBy.add("orderby");
this.orderByPara.put(key,value);
return this;
} public Bulider NotEqual(String key , Object value){
this.not = new ArrayList<>();
this.notPara = new LinkedHashMap<>();
this.not.add("!=");
this.notPara.put(key,value);
return this;
} public Bulider In(String key , Object ... values){
this.in = new ArrayList<>();
this.inPara = new LinkedHashMap<>();
List list = new ArrayList();
for (Object value : values) {
list.add(value);
}
this.in.add("in");
this.inPara.put(key,list);
return this;
} public Bulider NotIn(String key , Object ... values){
this.notIn = new ArrayList<>();
this.notInPara = new LinkedHashMap<>();
List list = new ArrayList();
for (Object value : values) {
list.add(value);
}
this.notIn.add("notin");
this.notInPara.put(key,list);
return this;
} public Bulider Limit(Integer value1 , Integer value2){
this.limit = new ArrayList<>();
this.limitPara = new LinkedHashMap<>();
List<Integer> list = new ArrayList();
list.add(value1);
list.add(value2);
this.limit.add("limit");
this.limitPara.put("limit",list);
return this;
} public Params build() {
return new Params(this);
}
} }
Params
4 我的测试类
package com.hhsj.controller; import com.hhsj.base.Params;
import com.hhsj.base.Result;
import com.hhsj.entity.DevUser;
import com.hhsj.repository.BaseRepositoryImpl;
import com.hhsj.service.impl.DevUserServiceImpl;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.PrivateKeyResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.*; @RestController
public class UserController {
@Autowired
private BaseRepositoryImpl baseRepository; @GetMapping("/cs/save")
public Boolean csSave(){
DevUser devUser = new DevUser();
devUser.setUsername("xxasdasdasdasdasdasdasd");
devUser.setPassword("dddfadadadasdasd");
return baseRepository.save(devUser);
} @GetMapping("/cs/findById")
public DevUser csF(){
return (DevUser) baseRepository.findByid(DevUser.class,5);
} @GetMapping("/cs/delbyid")
public Boolean csDelById(){
return baseRepository.deleteById(DevUser.class,5);
} @GetMapping("/cs/findByField")
public List<DevUser> csFindByField(){
return baseRepository.findByField(DevUser.class,"username","1");
} @GetMapping("/cs/delByIds")
public boolean csdelByIds(){
List<Integer> list = new ArrayList<>();
list.add(8);
list.add(9);
return baseRepository.deleteByIds(DevUser.class,list);
} @GetMapping("/cs/findByFields")
public List<DevUser> csFindByFields(){
LinkedHashMap map = new LinkedHashMap();
map.put("username","12");
map.put("password","dddf");
return baseRepository.findByMoreFiled(DevUser.class,map);
} @GetMapping("/cs/del")
public Boolean csDel(){
DevUser devUser = new DevUser();
devUser.setId(6);
return baseRepository.delete(devUser);
} @GetMapping("/cs/upd")
public Boolean csUpd(){
DevUser devUser = new DevUser();
devUser.setId(3);
devUser.setUsername("123345567qweqwwwqe");
devUser.setPassword("asdaslkdaksdfviosdhfgsdbfkjhdasiofhasdfbdasihgo");
return baseRepository.update(devUser,devUser.getId());
} @GetMapping("/cs/getCount")
public Integer csgetCount(){
LinkedHashMap map = new LinkedHashMap();
map.put("username","1");
return baseRepository.findCount(DevUser.class,map);
} @GetMapping("/cs/findByParm")
public List<DevUser> csfindByParm(){
Params build = Params.builder().Euqal("password","wqeq").Like("username","%q%").OrderBy("id","desc").build();
return baseRepository.findByParams(DevUser.class, build);
}
}
UserController
4 yml文件
spring:
datasource:
url: jdbc:mysql://localhost:3306/test
username: root
password: 12345
driver-class-name: com.mysql.jdbc.Driver
jpa:
show-sql: true
4 附上通用的Result
package com.hhsj.base; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data; /**
* @author cnyuchu@gmail.com
* @date 2018/11/8 9:27
*/
@Data
public class Result<T> { private final String result; private final Integer code; private final String message; private final T data; private Result(Builder<T> builder) {
this.result = builder.result;
this.code = builder.code;
this.message = builder.message;
this.data = builder.data;
} public static<T> Result.Builder<T> builder() {
return new Result.Builder<>();
} public static class Builder<T> {
private String result; private Integer code; private String message; private T data; public Builder<T> code(Integer code) {
this.code = code;
return this;
} public Builder<T> message(String message) {
this.message = message;
return this;
} public Builder<T> result(String result) {
this.result = result;
return this;
} public Builder<T> success() {
this.result = "SUCCESS";
this.code = 200;
return this;
} public Builder<T> fail() {
this.result = "FAILURE";
this.code = 500;
return this;
} public Builder<T> data(T data) {
this.data = data;
return this;
} public Result<T> build() {
return new Result<>(this);
}
} @JsonIgnore
public Boolean isFailed(){
return this.code==500;
}
}
Result
5 自定义的beanUtils工具类,可复制不为null的属性
package com.hhsj.base; import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException; import java.util.HashSet;
import java.util.Set; /**
* BeanUtils
*
* @author zhuyoufeng
*/
public class BeanUtils extends org.springframework.beans.BeanUtils { public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors(); Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
} public static void copyPropertiesExcludeNull(Object source, Object target) throws BeansException {
org.springframework.beans.BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
}
}
BeanUtils
今天的代码就这么多了,有问题一起探讨,谢谢各位。
qq :1508952532
spring data jpa 之 通用接口的更多相关文章
- Spring Data JPA 简单查询--接口方法
一.接口方法整理速查 下表针对于简单查询,即JpaRepository接口(继承了CrudRepository接口.PagingAndSortingRepository接口)中的可访问方法进行整理.( ...
- Spring Data JPA简单查询接口方法速查
下表针对于简单查询,即JpaRepository接口(继承了CrudRepository接口.PagingAndSortingRepository接口)中的可访问方法进行整理.(1)先按照功能进行分类 ...
- Spring Data Jpa使用QueryDsl接口出现的一些问题
1.QuerydslPredicateExecutor当实现此接口时,如果出现什么什么类没有找到的时候,请确认相关的querydsl依赖是否已经添加到maven依赖中 <dependency&g ...
- Spring Data JPA的Respository接口中查询方法
- Spring data jpa 使用技巧记录
软件152 尹以操 最近在用Springboot 以及Spring data jpa ,使用jpa可以让我更方便的操作数据库,特开此帖记录使用jpa的一些小技巧. 一.使用spring data j ...
- Spring Data JPA整合REST客户端Feign时: 分页查询的反序列化报错的问题
Type definition error: [simple type, class org.springframework.data.domain.Page]; nested exception i ...
- 转:使用 Spring Data JPA 简化 JPA 开发
从一个简单的 JPA 示例开始 本文主要讲述 Spring Data JPA,但是为了不至于给 JPA 和 Spring 的初学者造成较大的学习曲线,我们首先从 JPA 开始,简单介绍一个 JPA 示 ...
- 深入浅出学Spring Data JPA
第一章:Spring Data JPA入门 Spring Data是什么 Spring Data是一个用于简化数据库访问,并支持云服务的开源框架.其主要目标是使得对数据的访问变得方便快捷,并支持map ...
- Spring Data Jpa配置
Spring Data JPA提供的接口,也是Spring Data JPA的核心概念: 1:Repository:最顶层的接口,是一个空的接口,目的是为了统一所有Repository的类型,且能让组 ...
随机推荐
- java 数据结构(六):数组与集合
1. 集合与数组存储数据概述:集合.数组都是对多个数据进行存储操作的结构,简称Java容器.说明:此时的存储,主要指的是内存层面的存储,不涉及到持久化的存储(.txt,.jpg,.avi,数据库中) ...
- 机器学习实战基础(二十四):sklearn中的降维算法PCA和SVD(五) PCA与SVD 之 重要接口inverse_transform
重要接口inverse_transform 在上周的特征工程课中,我们学到了神奇的接口inverse_transform,可以将我们归一化,标准化,甚至做过哑变量的特征矩阵还原回原始数据中的特征矩阵 ...
- Django框架01 / http协议、web框架本质
Django框架01 / http协议.web框架本质 目录 Django框架01 / http协议.web框架本质 1.http协议 1.1 http协议简介 1.2 什么是http协议 1.3 H ...
- Angular 懒加载找不到模块问题解决方法
问题: 懒加载无法找到模块 解决办法: 在app-routing.module.ts中引入该模块
- git的撤销、删除和版本回退
目录 备注: 知识点: 查看git仓库的状态 查看历史记录. 版本回退 备注: 本文参考于廖雪峰的博客Git教程.依照其博客进行学习和记录,感谢其无私分享,也欢迎各位查看原文. 知识点: 1.git ...
- 深入理解Java虚拟机--个人总结(持续更新)
深入理解Java虚拟机--个人总结(持续更新) 每天按照书本学一点,会把自己的总结思考写下来,形成输出,持续更新,立帖为证 -- 2020年7月7日 开始第一次学习 -- 2020年7月8日 今天在百 ...
- webStrom中配置nodejs
1.安装nodejs 下载地址:node.js:https://nodejs.org/download/ 按照提示安装即可 2.安装WebStrom 按照提示安装即可 下载地址:webstorm:ht ...
- JAVA 实现将多目录多层级文件打成ZIP包后保留层级目录下载 ZIP压缩 下载
将文件夹保留目录打包为 ZIP 压缩包并下载 上周做了一个需求,要求将数据库保存的 html 界面取出后将服务器下的css和js文件一起打包压缩为ZIP文件,返回给前台:在数据库中保存的是html标签 ...
- MySQL数据库---记录相关操作
序 表中记录的相关操作一共四种:插入,更新,删除.查询.其中使用最多,也是最难的就是查询. 记录的插入 1. 插入完整数据(顺序插入) 语法一: INSERT INTO 表名(字段1,字段2,字段3… ...
- Teambition如何使用二次验证码/虚拟MFA/两步验证/谷歌验证器?
一般点账户名——设置——安全设置中开通虚拟MFA两步验证 具体步骤见链接 Teambition如何使用二次验证码/虚拟MFA/两步验证/谷歌验证器? 二次验证码小程序于谷歌身份验证器APP的优势 1 ...