1.如果参数为自定义对象,则通过属性名直接获取对象中属性的值。 public void updateUser(User user); //参数为user对象 <update id="updateUser" parameterType="com.mi.mybatis.model.User"> update tbl_user set user_name=#{user_name},user_password=#{user_password} where user_id=#{user_id}; /*使用属性名传递参数(parameterType指定参数的类型)*/ </update> 2.如果参数为单个基本类型的参数,则可以使用任意名字取值。 public User queryUserById(int userId); //参数为int型的userId <select id="queryUserById" resultType="User"> select * from tbl_user where user_id=#{id}; /*参数可以为id,userid,a1,...任意名字*/ </select> 3.如果参数为多个参数,则默认情况下MyBatis将这些参数自动注入到argue0,arg1,arg2...或param1,param2,param3...参数名中。在Mapper.xml文件需要使用arg0,param1这样的参数名获取参数值。 public User login(String username,String password); <select id="login" resultType="User"> /*select * froselem tbl_user where user_name=#{arg0} and user_password=#{arg1};*/ select * f
2.映射器参数传递 命名参数
于 2022-07-10 23:53:10 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)