1.新建entity
多对多的处理方式,在中间表的实体假如一对一
一对多的处理方式
2.创建dao
复杂sql直接在这里编写sql,然后直接调用dao方法
3.创建实体类并提供与entity的转换构造方法
4.repo层:业务处理,增删改加事务,调用dsl
5.dsl层:jpa处理,封装实体类返回,limit的处理方式
6.where多个条件需要判断的处理方式以及like处理方式
7.in的处理方式
8.文本类型需要处理
9.in后面可以直接加子查询,而form后面则不行,除非用queryDsl + blaze-persistence
10.对于需要表名动态拼接,可以写一个拦截器NamingInterceptor 继承EmptyInterceptor,重写onPrepareStatement方法对sql预处理。可以定义一个ThreLocal进行存储拼接内容
11.jpa很多时候返回的是Tuple类型(只要是查询多个指定字段就是返回Tuple类型),这时候可以使用Projections.bean(),返回指定泛型
public List<BizType> findBizByMsgType(int userId, int msgType) {
JPAQuery<BizType> query = queryFactory.select(Projections.bean(
BizType.class, businessTypeEntity.id,
businessTypeEntity.name, businessTypeEntity.startTime, businessTypeEntity.endTime,
businessTypeEntity.type, ub.busType)).from(ub).leftJoin(businessTypeEntity).on(ub.typeId.eq(businessTypeEntity.id)).
leftJoin(bs).on(ub.typeId.eq(bs.biztypeId)).leftJoin(es).on(bs.enterpriseSpecnumBindId.eq(es.id));
if (msgType==2){
query.leftJoin(sn).on(es.specnumId.eq(sn.id)).leftJoin(cc).on(sn.channelId.eq(cc.id));
}
return query.where(ub.userId.eq(userId).and(es.msgType.eq(msgType)).and(businessTypeEntity.state.eq(1))).
orderBy(businessTypeEntity.id.asc()).fetch();
}
- update的时候,多个字段使用多个set实现.