@ mybatis-config.xml
1 2 3
| <mappers> <mapper resource="mybatis/xml/UserMapper.xml" /> </mappers>
|
@ 添加GuestInfoMapper接口
1 2
| public interface UserMapper { void updateUserByUserNumber(UpdateUser updateUser);
|
@ 编写model类,用于包装参数
1 2 3 4 5 6
| package mybatis.model; public class UpdateUser { private String userNumber; private String firstName; private String docType; private String docTypeColumn;
|
@ 添加Mapper.xml,编写sql
UserMapper.xml
1 2 3 4 5 6 7 8 9
| <update id="updateUserByUserNumber" parameterType="mybatis.model.UpdateUser"> UPDATE NAME SET firstname = sfirstname = ${docTypeColumn} = WHERE name_id = </update>
|
@ 调用接口方法,注意update时需要commit
1 2 3 4
| SqlSession session = sqlSession.get() UserMapper mapper = session.getMapper(UserMapper.class) mapper.updateUserByUserNumber(updateUser) session.commit()
|