package com.cn.mapper; import com.cn.model.Client; import com.cn.model.Meter; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by Administrator on 2018-04-17. */ @Component("MeterMapper") public interface MeterMapper { //增加客户信息 void addBathClient(List<Meter> meterList); //分页查询数据 List<Meter> queryData(Map<String,Integer> map); //查询数据总数 int queryCount(); }
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.cn.mapper.MeterMapper"> <!--批量增加客户信息--> <insert parameterType="java.util.ArrayList" > insert into tb_meter (appId,serviceId,deviceId,gatewayId,status,timestamp) VALUES <foreach collection="list" item="item" separator=","> (#{item.appId},#{item.serviceId},#{item.deviceId},#{item.gatewayId},#{item.status},#{item.timestamp}) </foreach> </insert> <!--分页查询数据,根据limit和page进行分页--> <select parameterType="Map" resultType="com.cn.model.Meter"> SELECT id,appId,serviceId,deviceId,gatewayId,status,timestamp FROM tb_meter <if test="page!=null and limit!=null"> limit #{page},#{limit} </if> </select> <!--查询记录总数--> <select resultType="java.lang.Integer"> SELECT count(*) FROM tb_meter </select> </mapper>
model层代码
public class Meter implements Serializable{ private Integer id; private String appId; private String serviceId; private String deviceId; private String gatewayId; private Integer status; private String timestamp; public Meter() { } public Meter(Integer id, String serviceId, String appId, String deviceId, String gatewayId, Integer status, String timestamp) { this.id = id; this.serviceId = serviceId; this.appId = appId; this.deviceId = deviceId; this.gatewayId = gatewayId; this.status = status; this.timestamp = timestamp; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getAppId() { return appId; } public void setAppId(String appId) { this.appId = appId; } public String getServiceId() { return serviceId; } public void setServiceId(String serviceId) { this.serviceId = serviceId; } public String getDeviceId() { return deviceId; } public void setDeviceId(String deviceId) { this.deviceId = deviceId; } public String getGatewayId() { return gatewayId; } public void setGatewayId(String gatewayId) { this.gatewayId = gatewayId; } public Integer getStatus() { return status; } public void setStatus(Integer status) { this.status = status; } public String getTimestamp() { return timestamp; } public void setTimestamp(String timestamp) { this.timestamp = timestamp; } @Override public String toString() { return "Meter{" + "appId='" + appId + '\'' + ", serviceId='" + serviceId + '\'' + ", deviceId='" + deviceId + '\'' + ", gatewayId='" + gatewayId + '\'' + ", status=" + status + ", timestamp='" + timestamp + '\'' + '}'; } }
ResponseData的代码: