1、parameterType为String时,需要在mapper接口中定义@Param要传入的字符串名 UserMappper.xml
<select id="selectedUser" resultType="com.xxx.User" parameterType="String">
SELECT user_Id AS userId, user_Name AS userName FROM users WHERE user_id = #{userId} AND user_name = #{userName}
</select>
List<User> selectedUser(@Param("userId") String userId,@Param("userName") String userName);
2、parameterType为对象时,因为已经在对象中定义了属性,所以在mapper接口中就不要添加了@Param或者什么标注了
<update id="updateUser" parameterType="com.xxx.user">
UPDATE tb_user SET user_name=#{userName},user_sex=#{userSex}
WHERE user_id=#{userId}
</update>
int updateUser(User user);
3、parameterType为对象时可加可不加@Param注解,但是parameterType为String时必须加@Param