@Mapper public interface UserMapper {User selectById(int id);User selectByName(String username);User selectByEmail(String email);int insertUser(User user);int updateStatus(int id, int status);int updateHeader(int id, String headerUrl);int updatePassword(int id, String password); }
xml文件的格式可以在mybatis官网找到,直接复制进文件就行。
username, password, salt, email, type, status, activation_code, header_url, create_time id, username, password, salt, email, type, status, activation_code, header_url, create_time insert into user ( )values(#{username}, #{password}, #{salt}, #{email}, #{type}, #{status}, #{activationCode}, #{headerUrl}, #{createTime}) update user set status = #{status} where id = #{id} update user set header_url = #{headerUrl} where id = #{id} update user set password = #{password} where id = #{id}
五、测试从数据库中查找
@Test public void testSelectUser() {User user = userMapper.selectById(101);System.out.println(user);user = userMapper.selectByName("liubei");System.out.println(user);user = userMapper.selectByEmail("nowcoder101@sina.com");System.out.println(user); }