2024年4月14日 12点16分

This commit is contained in:
starlight_0208 2024-04-14 12:16:34 +08:00
parent 1631b844bb
commit ff73211d44
3 changed files with 28 additions and 6 deletions

View File

@ -23,14 +23,15 @@ public class Main3 {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
User user = new User();
user.setUsername("genshinImpact");
user.setPassword("Launch");
user.setUsername("Genshin Impact");
user.setPassword("Launch!");
user.setGender("");
user.setProvince("北京");
user.setCity("北京");
user.setProvince("上海");
user.setCity("上海");
user.setId(8);
// 执行查询
userMapper.addUser(user);
System.out.println(user.getId());
int changedLine = userMapper.updateUser(user);
System.out.println("Line Changed: " + changedLine);
// 提交事务
sqlSession.commit();

View File

@ -14,4 +14,5 @@ public interface UserMapper {
List<User> selectUserByConfidences(User user);
void addUser(User user);
int updateUser(User user);
int updateUserInfo(User user);
}

View File

@ -81,6 +81,26 @@
city = #{city}
where id = #{id};
</update>
<update id="updateUserInfo">
update tb_user
<set>
<if test="username != null and user != ''">
username = #{username}
</if>
<if test="password != null and password != ''">
password = #{password}
</if>
<if test="gender != null and gender != ''">
gender = #{gender}
</if>
<if test="province != null and province != ''">
province = #{province}
</if>
<if test="city != null and province != ''">
city = #{city}
</if>
</set>
</update>
</mapper>