mapper.xml的代码:
<select id="findByCurrentMonthScheduler" parameterType="java.util.HashMap" resultType="java.util.Map" > select id,text,start_date,end_date from sys_scheduler <where> <if test="minDate!=null and maxDate!=null"> createtime between #{minDate} and #{maxDate} </if> <if test="ischeck!=null"> and ischeck=#{ischeck}</if> <if test="isdelete!=null"> and isdelete=#{isdelete}</if> <if test="loginUserId!=null and loginUserId>1"> and companyid=#{companyid}</if> </where> </select>
然后在service层里打印出来一看,发现有以下的数据返回了:
id:1 ID:1 text:测试数据 TEXT:测试数据 ....
每一个值都是有重复的数据的,于是上网搜索了一翻,有人说将大写的过滤掉就可以了,但感觉这个办法不可行,因为map里毕竟都多了一倍的数据在,于是上Q群问,同样没有答案,后来有一个朋友帮忙搜到一个解决的办法(看来搜索关键字有待提高呀!):将查询的字段起一个大写的别名,一定要大写,如果用小写的话问题依然一样的。经测试,的确是可以解决了重复的问题,但感觉还是不太好!
后来自己想了一下,既然用resulMap是可以返回一个javaBean的,那我再定义多一个resultMap让它返回Map不就可以了吗?于是:
<resultMap id="SchedulerFindMap" type="java.util.LinkedHashMap" > <id column="id" property="id" jdbcType="BIGINT" /> <result column="text" property="text" jdbcType="VARCHAR" /> <result column="start_date" property="start_date" jdbcType="DATE" /> <result column="end_date" property="end_date" jdbcType="DATE" /> </resultMap>
再将查询的改为:
<select id="findByCurrentMonthScheduler" parameterType="java.util.HashMap" resultMap="SchedulerFindMap" > ....其它的一样 </select>
再测试,结果一切正常!!