部门页面的回显

   日期:2020-11-05     浏览:160    评论:0    
核心提示:首先查询出当前用户的数据,然后在查询出所有的部门DeptControl@Controller@RequestMapping("/dept")public class DeptControl { @Autowired IDeptService iDeptService; private static final Logger l = LoggerFactory.getLogger(DeptControl.class); @RequestMapping(path..

  • 首先查询出当前用户的数据,然后在查询出所有的部门

DeptControl

@Controller
@RequestMapping("/dept")
public class DeptControl { 

    @Autowired
    IDeptService iDeptService;
    private static  final Logger l = LoggerFactory.getLogger(DeptControl.class);
    @RequestMapping(path="/toList",method ={  RequestMethod.GET, RequestMethod.POST})
    public String toList(Model model, Integer curr, Integer pageSize, String companyId){ 
        l.info("toList curr = "+curr);
        l.info("toList pageSize = "+pageSize);
        l.info("toList companyId = "+companyId);
        //查询一个分页
        if (curr==null){ 
            curr=1;
        }
        if (pageSize==null){ 
            pageSize=10;
        }
        PageInfo<Dept> pi = iDeptService.findByPage(curr, pageSize, companyId);
        l.info("toList pi = "+pi);
        model.addAttribute("pi",pi);
        return "system/dept/dept-list";
    }
    // ${path}/system/dept/toUpdate.do?deptId=${dept.deptId}
    @RequestMapping(path="/toUpdate",method ={  RequestMethod.GET, RequestMethod.POST})
    public String toUpdate(Model model, String deptId){ 

        String companyId = "1";
        l.info("toUpdate deptId="+deptId);

        //查询部门
        Dept dept = iDeptService.findById(deptId);
        l.info("toUpdate dept="+dept);
        List<Dept> list = iDeptService.findAll(companyId);
        model.addAttribute("dept",dept);
        model.addAttribute("list",list);

        return "system/dept/dept-update";
    }



}

IDeptService

public interface IDeptService { 
    PageInfo<Dept> findByPage(int curr, int pageSize, String companyId);
    Dept findById(String deptId);
    List<Dept> findAll(String companyId);
}

DeptServiceImpl

@Service
public class DeptServiceImpl implements IDeptService { 
    @Autowired
    IDeptDao iDeptDao;

    public PageInfo<Dept> findByPage(int curr, int pageSize, String companyId) { 
        //调用dao查询所有的记录
        //select * from dept;
        //select count(*) from dept;
        //select * from dept limit 0,20;
        PageHelper.startPage(curr,pageSize);
        List<Dept> list =  iDeptDao.findDept();
        return new PageInfo<Dept>(list);
    }

    public Dept findById(String deptId) { 
        return iDeptDao.findDeptById(deptId);
    }

    public List<Dept> findAll(String companyId) { 
        List<Dept> list =  iDeptDao.findAllByDept(companyId);
        return list;
    }
}

IDeptDao

public interface IDeptDao { 
    //查询所有的部门记录
    List<Dept> findDept();
    Dept findDeptById(String id);
    List<Dept> findAllByDept(String companyId);//查询所有的部门名字
}

IDeptDao.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" >
<!--namespace: 需要映射的Dao接口类型-->
<mapper namespace="com.wlj.dao.dept.IDeptDao">
    <!--将查询结果映射到成员变量-->
    <resultMap id="findOneMap" type="dept">
        <id column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="company_id" property="companyId"/>
        <result column="company_name" property="companyName"/>
        <!-- 将parent_id 映射Dept类型-->
        <association property="parent"  column="parent_id" javaType="dept" select="findDeptById">
        </association>
    </resultMap>
    <select id="findDept" resultMap="findOneMap">
            select * from pe_dept
    </select>

    <select id="findDeptById" parameterType="string" resultMap="findOneMap">
        select  * from  pe_dept where dept_id = #{ id}
    </select>
    <select id="findAllByDept" parameterType="string" resultMap="findOneMap">
        select dept_name from pe_dept where company_id=#{ companyId}
    </select>
</mapper>


 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服