2.3 基于注解的Mybatis使用

2.3.1 在持久层接口中添加注解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/** 
*
* <p>Title: IUserDao</p>
* <p>Description: 用户的持久层操作</p>
* <p>Company: http://www.itheima.com/ </p>
*/
public interface IUserDao {
/**
* 查询所有用户
* @return
*/
@Select("select * from user")
List<User> findAll();
}

2.3.2 修改SqlMapConfig.xml

1
2
3
4
<!-- 告知mybatis映射配置的位置 --> 
<mappers>
<mapper class="com.itheima.dao.IUserDao"/>
</mappers>

2.3.3 注意事项:

在使用基于注解的Mybatis配置时,请移除xml的映射配置(IUserDao.xml)。