Jpa自定义SQL语句

参考:https://www.cnblogs.com/share-record/p/12262127.html

 @Query(value ="SELECT w.additional,w.amount,w.bank,w.bankCardNumber,w.bId,w.company,w.distributionChannel,w.expire,w.month ,\n" +
            "        w.name,w.number,w.particularYear,w.paymentMethod,w.paymentPeriod,w.payTime,w.premium,w.remark,w.takeEffect,w.renewalDate,\n" +
            "        TIMESTAMPDIFF(DAY, CURRENT_DATE,w.renewalDate) AS renewalDay,\n" +
            "        w.tId,w.time,w.type,w.wId,t.userName AS tName,b.userName AS bName,t.nickName AS nickName,t.mailbox AS mailbox \n" +
            "        FROM bd_warranty w\n" +
            "        LEFT JOIN bd_policyholderinfo t ON t.id = w.tId\n" +
            "        LEFT JOIN bd_insuredinfo b ON b.id = w.bId where TIMESTAMPDIFF(DAY, CURRENT_DATE,w.renewalDate) <= :day"+
            "        LIMIT :index,:size order by w.time DESC", nativeQuery = true)
    List<WarrantyVo> getPage(@Param("day") int day, @Param("index") int index , @Param("size") int size);

注意:nativeQuery = true

创建dto类WarrantyVo,SQL挂载在原有其他的mapper层。

posted @ 2022-05-01 20:37  别动我的猫  阅读(318)  评论(0编辑  收藏  举报