mybatisplus 对类的扩展属性的查询

定义的实体类,是与数据库关联的,单表操作没有问题,需要多表统计时,对该类进行了扩展,加了几个属性

vo类:

@Data
public class BatchVo implements Serializable {
    private static final long serialVersionUID = 1L;

    private  BatchNum pc;

    private String stuNumsTotal;
   
    private String stuNumsExam;

    private String zt;
}

这个类是对BatchNum的扩展

xml:

<resultMap id="batchVoMap" type="org.jeecg.modules.stu.exam.vo.BatchVo">
        <id property="pc.id" column="id"></id>
        <result property="pc.type" column="type"></result>
        <result property="pc.pcName" column="pc_name"></result>
        <result property="pc.stNameId" column="st_name_id"></result>
        <result property="pc.xqId" column="xq_id"></result>
        <result property="pc.ksrq" column="ksrq"></result>
        <result property="pc.beginTime" column="begin_time"></result>
        <result property="pc.endTime" column="end_time"></result>
        <result property="zt" column="zt"></result>
        <association property="stuNumsTotal" column="id" select="selStuNums"></association>
        <association property="stuNumsExam" column="id" select="selStuNumsExam"></association>

    </resultMap>

    <select id="selStuNums" resultType="java.lang.String">
        select count(0)  from xg_ks_stu
        where pc_id=#{id}
    </select>
    <select id="selStuNumsExam" resultType="java.lang.String">
        select count(0)  from xg_ks_stu
        where pc_id=#{id} and sub_time is not null
    </select>

    <select id="queryBatch" resultMap="batchVoMap">
        select *,
        case
        when (NOW() BETWEEN  CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',begin_time,':00') and CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',end_time,':59')) then 1
        when now()<![CDATA[>]]>CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',end_time,':59') then 2
        when now()<![CDATA[<]]>CONCAT(DATE_FORMAT(ksrq,'%Y-%m-%d'),' ',begin_time,':00') then 3
        end zt
        from xg_ks_pc
        order by create_time desc
    </select>

需要注意的是:<result property="zt" column="zt"></result> 必须放在 association 节的前边,放后边会报错,得此经验耗时半个小时

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值