mybatis中关于参数map和结果集map的 处理

@Test
public void   findmap() {
  
Map  map=new HashMap<>();
map.put("username", "老王");
/* u.username ='老王';*/
  List<Map<String,Object>>  map1=mapper.findmap(map);
  //转换成json数据返回给前端页面
  System.out.println(map1.size());
  System.out.println(map1);


}


<!-- if条件判断的时候要判断的是 最后的一层  其实就是盘但 要用到的 .此时写map!=null是不对的原因是此时的参数类型是类型不是具体的某个值 -->
<!-- 是值的判定而不是类型的判定 类型不能未null吧 -->
<select id="findmap"  parameterType="map"  resultType="map">
      SELECT  * from user  u inner JOIN  user_role  ur on u.id=ur.UID  join role r  on  ur.RID=r.ID   
        <where>
        <if  test="username !=null">
            and u.username=#{username}
           </if>
        </where>     
</select>

猜你喜欢

转载自blog.csdn.net/qq_34627002/article/details/80735222