model
public class User implements Serializable {
private Integer userId;
private String userName;
private String userAddress;
}
interface
public interface IUserDao {
int updateUser(User user);
}
mybatis.xml
<update id="updateUser" parameterType="com.User">
update user set username=#{username},birthday=#{birthday},sex=#{sex},
address=#{address} where id=#{id}
</update>
parameterType 属性:指定传入参数的类型
sql 语句中使用#{}字符:占位符,相当于原来 jdbc 部分所学的?
@Test
public void testUpdateUser()throws Exception{
User user = userDao.findById(5);
user.setAddress("北京");
int res = userDao.updateUser(user);
System.out.println(res);
}