MySQL语句可以查询到数据,为什么用MyBatis实现就查不到数据了
查询语句没错
我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 > DATE_FORMAT( #{query.startDateStr}, '%Y-%m-%d 00:00:00' )
</if>
<if test="query.endDateStr != null and query.endDateStr != '' ">
and log_operate_time < 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
sql打出来调一下就知道了
控制台打印一下sql看看
还有一种可能,看看连的数据库是不是一样