java web项目 demo_java web项目简单查询demo前后台完整代码

1、前台页面jsp

2、前台js

//添加搜索框

addSearchBox:function(width){

$('.searchbox').css({'width': width+'px'});

$('.searchbox-text').css({'width': eval(width-20)+'px'});

$('.datagrid-toolbar').append($('.serarchbox'));

$('.datagrid-toolbar').append($('#tbar'));

},

//查询

doSearch:function(value){

if($.trim(value) ==""){

Ict.info("请输入查询条件!");

return;

}

$('#systemUserGrid').datagrid({

url : '/pc/systemUser/queryUserList.htm',

queryParams : {

'keyWord' : value,

},

toolbar : '#toolBar'

});

},

3、后台controller

/**

* 查询系统用户列表.

* @param page

* @param rows

* @param idIcon

* @param keyWord

* @return Map

*/

@RequestMapping("queryUserList.htm")

@ResponseBody

public Map queryUserList(int page, int rows, String idIcon,String keyWord){

User user = SecurityContextUtil.getCurrentUser();

String companyId = SecurityContextUtil.getCompanyId();

String roleCode = user.getRoles().get(0).getRoleCode();

String[] typeAndId = new String[]{};

String departmentIds = "";

String employeeId = "";

if("0".equals(roleCode)){

if(StringUtils.hasText(idIcon)){

typeAndId = idIcon.split("_");

if("company".equals(typeAndId[1])){

companyId = typeAndId[0];

}else{

Department department = this.departmentService.getEntity(typeAndId[0]);

departmentIds = this.departmentService.allChildrenDept(department.getDepartmentId());

}

}else{

companyId = "";

departmentIds = "";

}

}else if("4".equals(roleCode)){

if(StringUtils.hasText(idIcon)){

typeAndId = idIcon.split("_");

if("company".equals(typeAndId[1])){

companyId = typeAndId[0];

}else{

departmentIds = this.departmentService.allChildrenDept(typeAndId[0]);

}

}else{

departmentIds = "";

}

}else if("3".equals(roleCode)){

Employee employee = this.sysEmployeeService.getEmployee(user.getEmployeeId());

if(StringUtils.hasText(idIcon)){

typeAndId = idIcon.split("_");

if("company".equals(typeAndId[1])){

companyId = typeAndId[0];

departmentIds = this.departmentService.allChildrenDept(employee.getDepartmentId());

}else{

departmentIds = this.departmentService.allChildrenDept(typeAndId[0]);

}

}else{

departmentIds = this.departmentService.allChildrenDept(employee.getDepartmentId());

}

}else{

employeeId = user.getEmployeeId();

}

return this.systemUserPCService.queryUserList(page, rows, keyWord, departmentIds, companyId, employeeId);

}

4.后台service层

public Map queryUserList(int page, int rows, String keyWord,String departmentIds, String companyId, String employeeId) {

return this.systemUserPCDao.queryUserList(page, rows , keyWord, departmentIds, companyId, employeeId);

}

5、后台dao层

public Map queryUserList(int page, int rows,             String keyWord,String departmentIds, String companyId, String employeeId) {         int offset = (page - 1)* rows;         String rowSql = "SELECT ur.id as id , "                 + "com.company_name AS companyName , "                 + " ro.role_name AS roleName , "                 + " emp.employee_code AS employeeCode  , "                 + " emp.employee_name AS realName , "                 + " su.user_name AS userName, "                 + " emp.mobile AS mobile ,"                 + " su.login_time AS loginTime "                 + " FROM tb_c_user_role ur ,tb_c_role ro , tb_c_system_user su , "                 + " tb_c_company com ,tb_c_employee emp "                 + " WHERE com.company_id = su.company_id  "                 + " AND su.user_id = ur.user_id AND ro.role_id = ur.role_id "                 + "AND emp.employee_id = su.employee_id "                 + " AND su.del_flag = '0' ";         String countSql = "select count(ur.id) "                 + " FROM tb_c_user_role ur ,tb_c_role ro , tb_c_system_user su , "                 + " tb_c_company com ,tb_c_employee emp "                 + " WHERE com.company_id = su.company_id  "                 + " AND su.user_id = ur.user_id AND ro.role_id = ur.role_id "                 + " AND emp.employee_id = su.employee_id "                 + " AND su.del_flag = '0' ";         if(StringUtils.hasText(departmentIds)){             rowSql += " AND emp.employee_id IN ( SELECT a.employee_id FROM tb_c_employee a , "                     + " tb_c_department b WHERE a.department_id = b.department_id AND b.department_id IN( "                     + departmentIds + " ))";             countSql += " AND emp.employee_id IN ( SELECT a.employee_id FROM tb_c_employee a , "                     + " tb_c_department b WHERE a.department_id = b.department_id AND b.department_id IN( "                     + departmentIds + " ))";         }         if(StringUtils.hasText(companyId)){             rowSql += " and com.company_id = '" + companyId + "' ";             countSql += " and com.company_id = '" + companyId + "' ";         }         if(StringUtils.hasText(employeeId)){             rowSql += " and emp.employee_id = '" + employeeId + "' ";             countSql += " and emp.employee_id = '" + employeeId + "' ";         }         if(StringUtils.hasText(keyWord)){             rowSql += "and ( emp.employee_name like '%" + keyWord.trim() + "%' or emp.mobile like '%"         + keyWord.trim() + "%' )";             countSql += "and ( emp.employee_name like '%" + keyWord.trim() + "%' or emp.mobile like '%"         + keyWord.trim() + "%' )";         }         rowSql += " limit ?,?";         List>  list = this.jdbcTemplate.queryForList (rowSql, offset, rows);         int total = this.jdbcTemplate.queryForInt(countSql);         Map map = new HashMap<>();         map.put("rows", list);         map.put("total", total);         return map;     }

你可能感兴趣的:(java,web项目,demo)