2019独角兽企业重金招聘Python工程师标准>>>
在MyBatis中可以用以下的方式来传递多个参数
1. 用java.util.Map来传递, Code 如下:
public List<User> getAllUsersByUserName(String username, int start, int limit){Map<String,Object> params = new HashMap<String, Object>(3);params.put("username",username);params.put("start",start);params.put("limit",limit);return userMapper.getAllUsersByUserName(params);}
对应的XXMapper.xml文件中如下:
<select id="getAllUsersByUserName" parameterType="map" resultType="User">SELECT u.* FROM User u WHERE u.username LIKE #{username} '%' LIMIT #{start}, #{limit}</select>
2. 用JavaBean的方式来传递, Code如下:
public List<User> getUsersByUserName(String username){User user = new User();user.setUsername(username);return userMapper.getUserByUsername(user);}
对应的XXMapper.xml文件中如下:
<select id="getAllUsersByUserName" parameterType="User" resultType="User">SELECT u.* FROM User u WHERE u.username = #{username} </select>
3.使用@Param这个注解,对应的XXMapper.xml文件同上
List<User> getAllUsersByUserName(@Param("username")String name, @Param("start")Integer start, @Param("limit")Integer limit);