dao接口中定义了3个参数,一个是对象类型,其余2个是基本类型
public List<MaintainAndDevice> queryMaintainDevice(@Param("mad")MaintainAndDevice mad,
@Param("page")Integer page,@Param("limit")Integer limit);
多个参数:使用注解的方式实现
实体对象:实体对象跟普通类型参数传递方法一样,只是在用的时候,以 对象名.(点)对象属性名 的方式调用就可以了。
<select id="queryMaintainDevice" resultType="com.zxhzn.firecontrol.fireMaintain.entity.MaintainAndDevice">
select
f.wid,f.fdid,f.wdate,f.reason,f.state,f.opuser,
d.region,d.devices_number,d.devices_type,d.devices_person_name
from sys_fire_maintain f
left join sys_devices d
on f.fdid=d.devices_id
<where>
<if test="mad.state != null and mad.state !='' ">
and f.state = #{mad.state,jdbcType=VARCHAR}
</if>
<if test="mad.devicesPersonName != null and mad.devicesPersonName != '' ">
and d.devices_person_name = #{mad.devicesPersonName,jdbcType=VARCHAR}
</if>
<if test="mad.startTime != null and mad.startTime !=''">
and f.wdate > str_to_date(#{mad.startTime}, '%Y-%m-%d %H')
</if>
<if test="mad.endTime != null and mad.endTime !=''">
and f.wdate <= str_to_date(#{mad.endTime}, '%Y-%m-%d %H')
</if>
</where>
limit #{page},#{limit}
</select>
示例二
- dao层
List<HardwareQrCode> queryAllQRCode(@Param("hardwareQrCode") HardwareQrCode hardwareQrCode);
- xml层
<!--分页查询二维码信息-->
<select id="queryAllQRCode" resultType="com.zxhzn.wellLid.qrcode.entity.HardwareQrCode">
select
q.id,q.device_id,q.qr_code_no,q.qr_code_status,q.qr_code_type,q.qr_code_content,q.qr_code_picture,q.qrfile_name,
q.create_date,q.del_flag,h.hardware_id,h.hardware_name,h.hardware_type,
h.hardware_imei,h.hardware_imsi,h.will_lid_name,h.will_lid_number
from qr_code q
left join qr_code_hardware h
on q.device_id=h.id
<where>
<if test="hardwareQrCode!=null">
<if test="hardwareQrCode.qrCodeType !=null and hardwareQrCode.qrCodeType !='' ">
and q.qr_code_type=#{hardwareQrCode.qrCodeType,jdbcType=INTEGRE}
</if>
<if test="hardwareQrCode.qrCodeStatus !=null and hardwareQrCode.qrCodeStatus !='' ">
and q.qr_code_status=#{hardwareQrCode.qrCodeStatus,jdbcType=INTEGRE}
</if>
<if test="hardwareQrCode.deviceId !=null and hardwareQrCode.deviceId !='' ">
and q.device_id=#{hardwareQrCode.deviceId,dbcType=VARCHAR}
</if>
<if test="hardwareQrCode.willLidNumber !=null and hardwareQrCode.willLidNumber !='' ">
and h.will_lid_number=#{hardwareQrCode.willLidNumber,dbcType=VARCHAR}
</if>
<if test="hardwareQrCode.hardwareImei !=null hardwareQrCode.hardwareImei !='' ">
and h.hardware_imei=#{hardwareQrCode.hardwareImei,dbcType=VARCHAR}
</if>
and q.del_flag=0
</if>
</where>
</select>
- entity实体层
package com.zxhzn.wellLid.qrcode.entity;
public class HardwareQrCode {
//ID
private String id;
//OneNet的硬件设备ID
private String hardwareId;
//硬件设备名称
private String hardwareName;
//硬件设备类型
private String hardwareType;
//imei
private String hardwareImei;
//imsi
private String hardwareImsi;
//井盖名称
private String willLidName;
//井盖编号
private String willLidNumber;
//二维码唯一编号
private String qrCodeNo;
//二维码使用状态0未使用1已使用
private Integer qrCodeStatus;
//二维码种类:0安装版 1巡检版
private Integer qrCodeType;
//二维码内容
private String qrCodeContent;
//二维码图片的访问路径
private String qrCodePicture;
//二维码图片名称
private String qrfileName;
//创建时间
private String createDate;
//0未删除1逻辑删除
private Integer delFlag;
}
- dao层
List<HardwareQrCode> queryAllQRCode(@Param("hardwareQrCode") HardwareQrCode hardwareQrCode);
- service层
/**
* 按照条件查询所有
* @param page
* @param limit
* @param hardwareQrCode
* @return
*/
JSONObject queryAllQRCode(Integer page, Integer limit, HardwareQrCode hardwareQrCode);
@Override
public JSONObject queryAllQRCode(Integer page, Integer limit,HardwareQrCode hardwareQrCode) {
JSONObject json = new JSONObject();
PageHelper.startPage(page, limit);
List<HardwareQrCode> list = qrCodeMapper.queryAllQRCode(hardwareQrCode);
PageInfo<HardwareQrCode> pageInfo = new PageInfo<HardwareQrCode>(list);
json.put("list", pageInfo.getList());
json.put("status", 200);
json.put("total", pageInfo.getTotal());
//封装到ResultModel中会多一层result,前台会提示数据返回状态异常
//return ResultModel.renderSuccessResultModelList(json);
return json;
}
- controller层
@RequestMapping("/queryAllQRCode.do")
public JSONObject queryAllQRCode(Integer page, Integer limit, HardwareQrCode hardwareQrCode) {
JSONObject jsonObject = qrCodeService.queryAllQRCode(page, limit, null);
return jsonObject;
}