qq_45419214 2020-06-10 19:36 采纳率: 0%
浏览 177

请教一下关于Mybatis一对一、一对多中出现的不能查询到的问题。

请教一下关于Mybatis一对一、一对多中出现的问题。

    @Select("select * from employees limit #{limit} offset #{offset} ")
    @Results(id = "empMap", value = {
            @Result(id = true, property = "emp_id", column = "emp_id"),
            @Result(property = "emp_name", column = "emp_name"),
            @Result(property = "emp_email", column = "emp_email"),
            @Result(property = "emp_gender", column = "emp_gender"),
            @Result(property = "emp_dept_id", column = "emp_dept_id"),
            @Result(property = "department", column = "dept_id", javaType = Department.class,
                    one = @One(select = "com.sumaojin.dao.DeptDao.findByDeptId")),
    })
    List<Employees> getEmpListByLimitAndOffset(@Param("offset") int offset,@Param("limit") int limit);

    @Select("select * from employees where emp_dept_id = #{emp_dept_id}")
    @ResultMap("empMap")
    List<Employees> findEmpByDeptId(@Param("emp_dept_id") int emp_dept_id);

emp是员工、dept是部门,就是希望在查询员工的时候能查询出所属的部门信息,在查询部门的时候能出来其所有的员工,麻烦各位大佬帮我看一下我这有什么问题吗?怎么查询员工的时候不能查出来它的部门信息呢。以上是员工方面的代码,以下是部门方面的代码。

        @Select("select * from department where dept_id = #{dept_id}")
    @Results(id = "deptMap", value = {
            @Result(id = true, property = "dept_id", column = "dept_id"),
            @Result(property = "dept_name", column = "dept_name"),
            @Result(property = "dept_leader", column = "dept_leader"),
            @Result(property = "dept_employees", column = "emp_dept_id", javaType = Employees.class,
            many = @Many(select = "com.sumaojin.dao.EmpDao.findEmpByDeptId"))
    })
    Department findByDeptId(@Param("dept_id") int dept_id);
  • 写回答

1条回答 默认 最新

  • _Onelone丶 2020-06-11 09:27
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题