在dao中使用注解:
package cn.dao; import cn.mepu.User; import org.apache.ibatis.annotations.Select; import java.util.List; /** * @author shkstart * @create 2019-11-01 10:25 */ public interface UserDao { //创建查询所有方法 @Select("select * from user") List<User> findAll(); }
使用注解删除dao.xml的配置文件更改主配置文件为;
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/javaee"/> <property name="username" value="root"/> <property name="password" value="root"/> </dataSource> </environment> </environments> <!-- 指定映射文件--> <mappers> <mapper class="cn.dao.UserDao"></mapper> </mappers> </configuration>