service层:
@Override public User getUserInfo(Integer userId) { User user = userMapper.getUserInfo(userId); //省略 业务代码... return user; }
mapper层:
User getUserInfo(Integer userId);
mapper.xml:
按照顺序传参
注意mapper层和xml层!
service层:
@Override public User getUserInfo(Integer userId,String sex) { User user = userMapper.getUserInfo(userId,sex); //省略 业务代码... return user; }
mapper层:
User getUserInfo(Integer userId,String sex);
mapper.xml:
service层
@Overrid public User getUserInfo(Integer userId,String sex) { User user = userMapper.getUserInfo(userId,sex); //省略 业务代码... return user; }
mapper层:
User getUserInfo(@Param("userId")Integer userId,@Param("sex")String sex);
mapper.xml:
service层:
@Override public User getUserInfo(User user) { User userInfo = userMapper.getUserInfo(user); //省略 业务代码... return userInfo; }
mapper层:
User getUserInfo(User User);
mapper.xml:
service层:
@Override public User getUserInfo(Map map) { User user = userMapper.getUserInfo(map); //省略 业务代码... return user; }
mapper层:
User getUserInfo(Map map);
mapper.xml层:
这种情况其实使用场景比较少,因为上面的各种姿势其实已经够用了
service层:
@Override public User getUserInfo1(Integer userId,String sex) { User userInfo = new User(userId,sex); Mapmap=new HashMap (); map.put("user",userInfo); User userResult= userMapper.getUserInfo(map); //省略 业务代码... return userResult; }
mapper层:
User getUserInfo(Map map);
mapper.xml:
service层:
@Override public User getUserInfo(User user,Integer age) { User userResult = userMapper.getUserInfo(user,age); //省略 业务代码... return userResult; }
mapper层:
User getUserInfo(@Param("userInfo") User user,@Param("age") Integer age);
mapper.xml:
service层:
Listlist= new ArrayList>(); list. add(44); list. add(45); list. add(46); List sysUser= sysUserMapper. selectList(list);
mapper层:
ListselectList(List ids);
mapper.xml:
service层:
Listsysuser= sysUserMapper. selectlist(new Integer[]{44,45,46});
mapper层:
ListselectList(Integer[]ids);
mapper.xml:
使用这个的时候,只需要注意,如果是传递字段名或者表名,是直接做参数传入即可,
但是如果作为sql'语句里面使用的值, 记得需要手动拼接 ' ' 号。
例如, 传入单个参数 sex:
service层:
@Override public User getUserInfo(String sex) { sex="'"+sex+"'"; User user = userMapper.getUserInfo(sex); //省略 业务代码... return user; }
mapper层:
User getUserInfo(String sex);
mapper.xml:
多个参数,那也就是使用注解@Param取名字解决即可。