1、XML映射文件
1.1、mapper
public interface EmpMapper {
Emp queryByEmpNo(String empno);
}
1.2、xml
<?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="org.silence.spring.springbootdemo.mapper.EmpMapper">
<select id="queryByEmpNo" resultType="Emp" >
select * from EMP where EMPNO = #{empno}
</select>
</mapper>
1.3、test
@Test
void queryByEmpNo() {
Emp emp = mapper.queryByEmpNo("7499");
System.out.println(emp);
}
2、注解(不需要xml文件)
2.1、mapper
public interface DeptMapper {
@Select("select * from dept")
List<Dept> queryAll();
@Select("select * from dept where deptno = #{deptno}")
Dept queryByDeptno(String deptno);
}
2.2、test
@Test
void queryByDeptno() {
Dept dept = mapper.queryByDeptno("20");
System.out.println(dept);
}