一、实现内容
1.首相pojo类
package com.sql.slow.query.po;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class NodeWhiteList implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value="id", type= IdType.AUTO)
private Integer id;
private String hostIp;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date updateTime;
}
2.接着写mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sql.slow.query.dao.NodeWhiteListMapper">
<!-- 和数据库映射-->
<resultMap id="BaseResultMap" type="com.sql.slow.query.po.NodeWhiteList">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="host_ip" jdbcType="VARCHAR" property="hostIp" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<!--基本返回字段-->
<sql id="Base_Column_List">
id,host_ip,create_time,update_time
</sql>
<!--通过传入的条件查询节点白名单集合-->
<select id="selectNodeWhiteListByCondition" resultType="com.sql.slow.query.po.NodeWhiteList" >
select
<include refid="Base_Column_List" />
from
node_white_list
where
host_ip like "%"#{hostIp}"%"
order by create_time desc
</select>
<!-- 添加指定节点白名单数据-->
<insert id="insertNodeWhiteList"