PS:本文中的数据库是MySQL数据库。
如:数据库中的日期类型为 datetime。
CREATE TABLE `aiwarning` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`eventtime` datetime DEFAULT NULL COMMENT '事件时间',
`img` mediumtext CHARACTER SET latin1 COLLATE latin1_swedish_ci COMMENT '事件图片',
`event_type` varchar(2) DEFAULT NULL COMMENT '事件类型',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=154 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='事件表';
INSERT INTO `aiwarning` VALUES (149,'2022-06-06 15:37:30',NULL,'13');
INSERT INTO `aiwarning` VALUES (150,'2022-06-06 15:40:07',NULL,'10');
INSERT INTO `aiwarning` VALUES (153,'2022-09-20 08:40:07',NULL,'9');
Java类型为 Date类型。
@Data
public class Aiwarning{
/** 自增ID */
private Long id;
/** 事件时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date eventtime;
/** 事件图片 */
private String img;
/** 事件类型 */
private String eventType;
}
Mapper对应的xml文件
<select id="selectAiwarningList" parameterType="Aiwarning">
select id, eventtime, img, event_type from aiwarning
<where>
<if test="eventtime != null "> and LEFT(eventtime, 10) = LEFT( #{eventtime}, 10)</if>
<if test="img != null and img != ''"> and img = #{img}</if>
<if test="eventType != null and eventType != ''"> and event_type = #{eventType}</if>
</where>
</select>
PS:发博客,仅仅是当作学习的笔记~