快速学习Mybatis-基于注解的 Mybatis 使用

基于注解的 Mybatis 使用
在持久层接口中添加注解
public interface IUserDao {
    /**
     * 查询所有用户
     * @return
     */
    @Select("select * from user")
    List<User> findAll();
}
修改 SqlMapConfig.xml
<!-- 告知 mybatis 映射配置的位置 --> 
<mappers> 
	<mapper class="com.itheima.dao.IUserDao"/>
</mappers>
注意事项:

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

以上就是本文的全部内容,希望对大家的学习有所帮助。更多教程请访问码农之家

posted @ 2022-07-29 09:38  small_123  阅读(18)  评论(0编辑  收藏  举报