在抽象接口编辑注解
@Select("select * from user")
List<User> getUsers();
在mybatis-config.xml即mybatis核心配置文件中绑定接口
<!--绑定接口--> <mappers> <mapper class="com.zlc.dao.UserMapper"/> </mappers>
注意:简单sql语句推荐使用注解,复杂sql语句使用xml配置文件方式
目录结构
接口
package com.zlc.dao; import com.zlc.pojo.User; import org.apache.ibatis.annotations.Select; import java.util.List; public interface UserMapper { @Select("select * from user") List<User> getUsers(); }