MySQL语句可以查询到数据,为什么用MyBatis实现就查不到数据了

发布于 2022-09-12 23:46:19 字数 5941 浏览 15 评论 0

查询语句没错

我MySQL查询语句没错,可以查询到数据

SELECT rtp.license_number, rtp.begin_time, rtp.entry_time
FROM refuse_treatment_plant rtp
where rtp.license_number="京OFV501FV606" 
and DATE_FORMAT(entry_time,'%Y-%m-%d') BETWEEN "2021-05-15" and "2021-05-18"

在代码里实现

<select
            id="searchRefuseTreatmentPlantV1"
            resultType="com.bulldozer.entity.RefuseTreatmentPlant"
    >
        SELECT <include refid="Base_Column_List" />
        FROM refuse_treatment_plant
        <where>
            <!--添加if条件如果参数为空则不拼接sql-->
            <if test=" flagDelete!= null and flagDelete!= '' and flagDelete == 0">
                AND flag_delete = #{flagDelete}
            </if>
            <if test=" countType!= null and countType!= '' and countType == 'greater'">
                AND leave_count>entry_count
            </if>
            <if test=" countType!= null and countType!= '' and countType == 'less'">
                AND leave_count<![CDATA[ < ]]>entry_count
            </if>
            <if test=" licenseNumber != null and licenseNumber != '' ">
                AND license_number like concat('%',#{licenseNumber},'%')
            </if>
            <if test=" licenseNumber != null and licenseNumberType != null and
            licenseNumber != '' and licenseNumberType == 'equal'">
                AND license_number = #{licenseNumber}
            </if>
            <if test=" dateType != null and dateType== 'curDay'">
                AND to_days(warning_time) = to_days(NOW())
            </if>
            <if test=" timeStart != null and timeStart != '' and timeEnd != null and timeEnd != ''">
                AND DATE_FORMAT(entry_time, "%Y-%m-%d") BETWEEN #{timeStart} and #{timeEnd}
            </if>
            <if test=" timeStart != null and timeStart != '' ">
                <foreach collection="timeList" index="index" item="timeItem" open="AND (" close=")" separator="or" >
                    date(entry_time) = #{timeItem}
                </foreach>
            </if>

            <if test="startDateStr!=endDateStr">
                <if test="query.startDateStr != null and query.startDateStr != '' ">
                    and log_operate_time &gt;  DATE_FORMAT( #{query.startDateStr}, '%Y-%m-%d 00:00:00' )
                </if>
                <if test="query.endDateStr != null and query.endDateStr != '' ">
                    and log_operate_time &lt; DATE_FORMAT( #{query.endDateStr}, '%Y-%m-%d 23:59:59' )
                </if>
            </if>

        </where>

        <choose>
            <when test="sort=='ASC'">
                ORDER BY entryTime ASC limit #{start}, #{dataLength}
            </when>
            <otherwise>
                ORDER BY entryTime DESC limit #{start}, #{dataLength}
            </otherwise>
        </choose>
    </select>
@ApiOperation("搜索进消纳厂记录")
    @RequestMapping(value="/v1/search/refuse-treatment-plant", method={ RequestMethod.POST })
    public ResponseResult searchRefuseTreatmentPlantV1(
            HttpServletRequest request,
            @RequestBody Map<String, Object> map) {

//        System.out.println(map);
//        final List timeList = new ArrayList();

        if(map.get("timeStart") != null) {
            System.out.println(map.get("timeStart").toString());
            if(map.get("timeStart").getClass().isArray()) {
//                System.out.println("数组");
            } else {
//                System.out.println("字符串");
                String timeStartStr = map.get("timeStart").toString();
                map.put("timeStart", timeStartStr);
                timeStartStr = timeStartStr.substring(1, timeStartStr.length()-1);
//                System.out.println("timeStartStr == " + timeStartStr);
//                ArrayList<String> timeList = new ArrayList<>(Arrays.asList(
//                        timeStartStr.split(",")
//                ));
                String timeStartArray[] = timeStartStr.split(",");
                List<String> timeList = Arrays.asList(timeStartArray);
                map.put("timeList", timeList);
            }
        }

        System.out.println(map);
        List<RefuseTreatmentPlant> list = refuseTreatmentPlantService.searchRefuseTreatmentPlantV1(map);

        String message = "SUCCESS";
        String detail = "SUCCESS";
        JSONObject jsonResultObject = new JSONObject();
        jsonResultObject.put("list", list);
        return ResponseResult.ok(message, jsonResultObject, detail);
    }
    

自己打印了下语句

<if test=" timeStart != null and timeStart != '' and timeEnd != null and timeEnd != ''">
  AND DATE_FORMAT(entry_time, "%Y-%m-%d") BETWEEN #{timeStart} and #{timeEnd}
           </if>
           <if test=" timeStart != null and timeStart != '' ">
               <foreach collection="timeList" index="index" item="timeItem" open="AND (" close=")" separator="or" >
                   date(entry_time) = #{timeItem}
               </foreach>
           </if>

是这个的问题

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

才能让你更想念 2022-09-19 23:46:19

sql打出来调一下就知道了

鯉魚旗 2022-09-19 23:46:19

控制台打印一下sql看看
还有一种可能,看看连的数据库是不是一样

莫多说 2022-09-19 23:46:19

image.png

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文