欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

部门页面的回显

程序员文章站 2022-11-23 16:09:59
首先查询出当前用户的数据,然后在查询出所有的部门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>


本文地址:https://blog.csdn.net/wlj1442/article/details/109479202

相关标签: java