室内设计素材网站推荐,济南网络科技公司,网站建设施工方案,东营注册公司简单的数据查询#xff0c;我们可以在mapper接口里面去实现#xff0c;但是如果是复杂的查询#xff0c;我们就可以使用xml配置文件去做#xff0c; 官网链接xml配置文件
实现效果 实现代码 根据mapper接口的包结构#xff0c;在resources包里面新建同名同结构的xml文件…简单的数据查询我们可以在mapper接口里面去实现但是如果是复杂的查询我们就可以使用xml配置文件去做 官网链接xml配置文件
实现效果 实现代码 根据mapper接口的包结构在resources包里面新建同名同结构的xml文件 mapper接口文件
Mapper
public interface EmpMapper2 {public ListEmp getAllEmpList();
}resources里面对应的xml文件 namespace对应的是mapper接口的全类名 select里面的id对应的就是mapper接口里面的方法名 resultType 单条记录封装的类型
?xml version1.0 encodingUTF-8 ?
!DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttps://mybatis.org/dtd/mybatis-3-mapper.dtd
!-- mamper接口的全类名--
mapper namespacecom.gaofeng.mapper.EmpMapper2
!-- resultType 单条记录封装的类型--select idgetAllEmpList resultTypecom.gaofeng.pojo.Empselect * from tb_emp/select
/mapper查询测试
SpringBootTest
public class mybatisTestxml {Autowiredprivate EmpMapper2 empMapper2;Testpublic void getEmpList(){ListEmp allEmpList empMapper2.getAllEmpList();System.out.println(allEmpList);}
}条件查询
EmpMapper2文件
public ListEmp listEmp(String name,Short gender, LocalDate begin,LocalDate end);xml文件配置 select idlistEmp resultTypecom.itheima.pojo.Empselect * from tb_emp where name like concat(%,#{name},%) and gender #{gender}and entrydate between #{begin} and #{end} order by update_time desc;/select测试文件 Testpublic void testGetEmp(){ListEmp empList empMapper2.listEmp(张, (short) 1, LocalDate.of(2010, 1, 1), LocalDate.of(2020, 1, 1));System.out.println(empList);}