The first embodiment: the subscript parameter passing
DAO layer function method
Public User selectUser(String name, String area);
Corresponding Mapper.xml
<select id="selectUser" resultMap="BaseResultMap"> select * from user where name = #{0} and area = #{1} </select>
Description: Parameter Type can not write, # {0} is the first representative of the received parameter dao layer, # {1} represents a second parameter dao layer, subsequent parameters press so marked.
The second embodiment: map Package
DAO layer function method
Public User selectUser(Map<String, Object> paramMap);
Corresponding Mapper.xml
<select id="selectUser" parameterType="java.util.Map" resultMap="BaseResultMap">
select * from user where name = #{name,jdbcType=VARCHAR} and area = #{area, jdbcType=VARCHAR}
</select>
service layer calls
Map<String, Object> paramMap = new hashMap(); paramMap.put ( "name", "parameter value" ); paramMap.put ( "Area", "parameter value" ); User user = userDao.selectUser(paramMap);
The third scheme: use annotations @param
DAO layer function method
Public User selectUser(@param("name")String userName, @param("area")String userArea);
Corresponding Mapper.xml
<select id=" selectUser" resultMap="BaseResultMap"> select * from user where name = #{userName,jdbcType=VARCHAR} and area=#{userArea, jdbcType=VARCHAR} </select>
Description: In the few parameters, the recommended third embodiment, more intuitive.