要让查询结果只显示state为1的数据,可以在标签内添加条件判断:

<where>
  <if test="staffname!=null and staffname.length!=0">
    staff.staffname LIKE CONCAT('%', #{staffname}, '%')
  </if>
  <if test="branchname!=null and branchname.length!=0">
    branch.branchname LIKE CONCAT('%', #{branchname}, '%')
  </if>
  <if test="deptname!=null and deptname.length!=0">
    department.deptname LIKE CONCAT('%', #{deptname}, '%')
  </if>
  <if test="state!=null and state==1">
    AND staff.state = 1
  </if>
</where>

标签中添加一个条件判断,判断是否传入了state参数,并且判断state是否等于1,如果满足条件,则添加一个额外的条件语句AND staff.state = 1。

这样就可以限制查询结果只显示state为1的数据。

select id=getStaffs resultType=comaaamodelStaff SELECT staffstaffid staffstaffname staffidcard staffaddress staffphone staffentrytime branchbranchname

原文地址: https://www.cveoy.top/t/topic/jbRo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录