mybatis的使用
pom中导入Build
导入build使得idea扫描到xml配置文件
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
properties中配置
mybatis-plus.mapper-locations=classpath:com/xhb/service_edu/mapper/xml/*.xml
创建Dao对象
创建接口
@Repository
public interface EduTeacherMapper extends BaseMapper<EduTeacher> {
//方法中的参数@Param("aa")
List<EduTeacher> getAll();
}
创建对应的Mapper
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xhb.service_edu.mapper.EduTeacherMapper">
<select id="getAll" resultType="com.xhb.service_edu.entity.EduTeacher">
SELECT * FROM edu_teacher where a=#{aa}或者{0}//0代表第一个参数1代表第二参数
</select>
</mapper>