xml中根据各种字段进行查询
- 欲实现:
- 其中映射的类为:
- 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.ws.firestation.mapper.TradeRecordMapper"> <select id="listsome" resultType="com.ws.firestation.entity.po.TradeRecord"> select * from firecab.trade_record where 1=1 <if test= "goodsName !=null and goodsName !=''"> and goods_name like concat('%',#{goodsName},'%') </if> <if test= "serverId !=null and serverId !=''"> and server_id like concat('%',#{stationId},'%') </if> <if test= "cabintCatalogy !=null and cabintCatalogy !=''"> and cabint_catalogy=#{cabintCatalogy} </if> <if test= "Type !=null and Type !=''"> and type=#{Type} </if> <if test= "tradeStartTime !=null and tradeStartTime !=''"> and tradetime >= #{tradeStartTime} </if> <if test= "tradeEndTime !=null and tradeEndTime !=''"> and tradetime <= #{tradeStartTime} </if> </select> </mapper>
- 使用了if test的判断
- concat使用了MySQL的模糊查询
- 还使用了MySQL的大小与
还使用了MySQL的大小与
[外链图片转存中…(img-upsHOaP2-1623687371596)]
- 这样就能实现随意用户输入哪几个字段来进行查询。