springBoot项目jpa多表联查+动态sql,根据条件查询数据

项目场景:

项目用到了jpa多表联查加上动态查询


问题描述:

由于之前没接触过jpa项目,所以使用的的是原生sql语句开发,这个这个多表联查查询出来的数据是以数组的形式显示出来的,前边并没有属性,前端传不过去。
这个是之前代码。

 @Query(value = "SELECT b.student_class as student_class," +
            "a.activiteName as activiteName," +
            "a.templateId as templateId," +
            "a.student_answer as student_answer," +
            "a.state as state," +
            "a.student_id as student_id ," +
            "b.student_name as student_name," +
            "c.question as question," +
            "a.start_time as start_time," +
            "a.updata_time as updata_time," +
            "a.is_delete as is_delete FROM test1 a left JOIN test2 b on a.student_id = b.studentID left JOIN test3 c on c.id = a.templateId WHERE  a.is_delete = 0 " +
            " and if(:student_class = '' or :student_class is null ,1=1,student_class like %:student_class%)" +
            "and if(:activiteName = '' or :activiteName is null ,1=1,activiteName like %:activiteName%)" +
            "and if(:templateId =    '' or :templateId is null ,1=1,templateId =:templateId)" +
            "and if(:student_answer = '' or :student_answer is null ,1=1,student_answer like %:student_answer%)" +
            "and if(:state = '' or :state is null ,1=1,state like %:state%)" +
            "and if(:student_id = '' or :student_id is null ,1=1,student_id =:student_id)" +
            "and if(:student_name = '' or :student_name is null ,1=
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值