UserDao接口:
package com.qublog.dao;
import com.qublog.domain.User;
import org.apache.ibatis.annotations.*;
import java.util.List;
//在mybatis中针对crud一共有四个注解
//@Select @Insert @Update @Delete
public interface UserDao {
//查询所有用户
@Select(value = "select * from user;")
@Results(id = "userMap", value = {
@Result(id = true, column = "id", property = "userId"),
@Result(column = "username", property = "userName"),
@Result(column = "address", property = "userAddress"),
@Result(column = "sex", property = "userSex"),
@Result(column = "birthday", property = "userBirthday"),
})
List<User> findAll();
//根据id查询用户
@Select(value = "select * from user where id=#{id};")
@ResultMap(value = {"userMap"})
User findById(Integer id);
//根据用户名称模糊查询
@Select(value = "select * from user where username like #{username};")
@ResultMap(value = {"userMap"})
List<User> findUserByName(String username);
}