最近连着两个项目自己搭的都是JPA,一开始还不太习惯,最后觉得小项目用JPA实在是太香了,如果写写就能体会到了
HQL
直接干货,HQL包含了多表,条件判断、非等、自定义实体类
@Query(value = "select new com.yuanchuang.shop.vo.OrderGoodsInfoVo(og,oi.orderTime,oi.orderState) " +
"FROM OrderGoods og LEFT JOIN OrderInfo oi ON og.orderId=oi.id where og.goodsType LIKE (CASE WHEN ?1='' then '%%' else CONCAT('%',?1,'%') END) and " +
"og.goodsName LIKE (CASE WHEN ?2='' then '%%' else CONCAT('%',?2,'%') END) and og.goodsCode LIKE (CASE WHEN ?3='' then '%%' else CONCAT('%',?3,'%') END) " +
"and og.isrefund LIKE CONCAT('%',?5,'%') and og.isrefund<>0 and oi.orderTime >= ?4")
Page<OrderGoodsInfoVo> findOrderGoodsInfoHQLByIsRefund(String goodsType, String goodsName, String goodsCode, String orderTime, String isRefund, Pageable pageable);