野路子Map传递参数
作者:互联网
当遇到实体类属性过于庞大,或者数据库字段过多,不好查询所需要的数据,可以用Map传参。使用方法如下
1.编写接口中的方法(注意参数为Map)
//根据map查询用户
User getUserByID2(Map map);
2.编写Mapper.xml
<!--万能Map-->
<select id="getUserByID2" resultType="com.Google.pojo.User" parameterType="Map">
select * from user where id=#{userid}
</select>
3.实现
public void getUserByID2(){
SqlSession sqlSession = sqlSessionFactory.getsqlSession();
userMapper mapper = sqlSession.getMapper(userMapper.class);
Map<String, Object> map = new HashMap<>();
map.put("userid",3);
User userByID2 = mapper.getUserByID2(map);
System.out.println(userByID2);
sqlSession.close();
}
标签:Map,map,userMapper,sqlSession,参数,userByID2,getUserByID2,路子 来源: https://www.cnblogs.com/luoking/p/15816840.html