mybatis使用association分步查询关联属性查询

 时间:2024-10-12 22:32:46

1、我们的程序是要查询员工信息的时候查询出相应的部门信息。

mybatis使用association分步查询关联属性查询

3、定义员工信息返回的resultMap。<resultMap type="com.gwolf.bean.Employee" id="MyEmpByStep"> <id column="emp_id" property="empId"/> <result column="emp_name" property="empName"/> <result column="gender" property="gender"/> <result column="email" property="email"/> <result column="emp_name" property="empName"/> <association property="department" select="com.gwolf.dao.DepartmentMapper.getDepartmentById"></association> </resultMap>

mybatis使用association分步查询关联属性查询

5、编写单元测试类。@Test public void test1() throws Exception { Stri荏鱿胫协ng resource = "mybatis-config.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); try { EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class); Map<Integer,Object> employee = employeeMapper.getEmpByIdReturnMap(1); System.out.println(employee); }finally { sqlSession.close(); } }

mybatis使用association分步查询关联属性查询
  • ASP.NET软件工程师需要学习哪些技术知识
  • Eclipse插件开发教程3-插件的导出和安装应用
  • 使用idea 创建maven web 项目速度慢
  • 如何安装vmware player
  • vscode如何隐藏小地图
  • 热门搜索
    cad楼梯怎么画 笛梵洗发水怎么样 怎么给c盘增加空间 怎么自拍 北京林业大学怎么样 梦幻西游大唐怎么加点 车辆违章怎么查询 齐肩短发怎么扎好看 小黄鱼怎么做 怎么煮茶叶蛋