学习笔记012——MyBatis中根据时间模糊查询

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:发博客,仅仅是当作学习的笔记~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值