maven环境搭建及增删改查功能,带分页

pom.xml中配置所需jar


  4.0.0
  AntSource
  AntSource
  war
  0.0.1-SNAPSHOT
  AntSource Maven Webapp
  http://maven.apache.org
  
   
		
			javax.servlet
			javax.servlet-api
			3.1.0
			provided
		
		

		
		
			org.springframework
			spring-context
			4.3.11.RELEASE
		
		
			org.springframework
			spring-web
			4.3.11.RELEASE
		
		
			org.springframework
			spring-webmvc
			4.3.11.RELEASE
		
		

		
		
			org.springframework
			spring-jdbc
			4.3.11.RELEASE
		
		
			org.mybatis
			mybatis
			3.4.1
		
		
			org.mybatis
			mybatis-spring
			1.3.1
		
		
			mysql
			mysql-connector-java
			5.1.38
		
		

		
		
			javax.servlet
			jstl
			1.2
		
		

		
		
			com.google.code.gson
			gson
			2.8.1
		
		

		
		
			javax.annotation
			javax.annotation-api
			1.3.1
		
		

		
		
			jsptags
			pager-taglib
			2.0
		
		
		
		
		
			org.aspectj
			aspectjweaver
			1.8.10
		
		

  
  
    AntSource
  

resources下新建spring.xml




	
	
	
	

	
	
		
		
		
		
	

	
		
		
		
		
	

	
		
		
	
	

	
	
	

	
	

	
	
	

	
	
		
	
	
	


mybatis.xml中配置




  
  
  
  	
  

generator Config.xml中配置





	
	
	
		
			
			
			
		

		
		
		
		
		
		
		
		

		
		
		
			
			 
			   

Java代码

kohgylw.model下建      实体类Department.java

package kohgylw.model;

public class Department {
    private Integer departmentId;

    private String pId;

    private String departmentName;

    private String departmentTel;

    private String departmentDesc;

    private String departmentGer;

    private String departmentType;

    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public String getpId() {
        return pId;
    }

    public void setpId(String pId) {
        this.pId = pId;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public String getDepartmentTel() {
        return departmentTel;
    }

    public void setDepartmentTel(String departmentTel) {
        this.departmentTel = departmentTel;
    }

    public String getDepartmentDesc() {
        return departmentDesc;
    }

    public void setDepartmentDesc(String departmentDesc) {
        this.departmentDesc = departmentDesc;
    }

    public String getDepartmentGer() {
        return departmentGer;
    }

    public void setDepartmentGer(String departmentGer) {
        this.departmentGer = departmentGer;
    }

    public String getDepartmentType() {
        return departmentType;
    }

    public void setDepartmentType(String departmentType) {
        this.departmentType = departmentType;
    }

	
    
}

辅助分页插件 DepartmentPager.java

package kohgylw.model;

import java.util.List;

//辅助生成分页插件的
 
public class DepartmentPager {
	private int total;//总页码
	private int totalRecords;//总记录数
	private List listDepartments;//分页记录集合
	
	
	public int getTotal() {
		return total;
	}
	
	public void setTotal(int total) {
		this.total = total;
	}
	
	public int getTotalRecords() {
		return totalRecords;
	}
	
	public void setTotalRecords(int totalRecords) {
		this.totalRecords = totalRecords;
	}

	public List getListDepartments() {
		return listDepartments;
	}

	public void setListDepartments(List listDepartments) {
		this.listDepartments = listDepartments;
	}

	@Override
	public String toString() {
		return "DepartmentPager [total=" + total + ", totalRecords=" + totalRecords + ", listDepartments="
				+ listDepartments + "]";
	}
	
	
}

kohgylw.mapper下建接口      DepartmentMapper.java

package kohgylw.mapper;

import java.util.List;
import java.util.Map;

import kohgylw.model.Department;

public interface DepartmentMapper {
    int deleteByPrimaryKey(Integer departmentId);

    int insert(Department record);

    int insertSelective(Department record);

    Department selectByPrimaryKey(Integer departmentId);

    int updateByPrimaryKeySelective(Department record);

    int updateByPrimaryKey(Department record);
    //求部门总记录数
	int queryDepartmentNum(Map totalMap);

	List querydepartmentPage(Map map);
   //根据部门名称查询单个信息
	Department selectByDepartmentId(Integer departmentId);

	
	
}

kohgylw.mapper.xml下建接口实现类      DepartmentMapper.xml




  
    
    
    
    
    
    
    
  
  
    department_id, p_id, department_name, department_tel, department_desc, department_ger, 
    department_type
  
  
  
    delete from department
    where department_id = #{departmentId,jdbcType=INTEGER}
  
  
    insert into department (department_id, p_id, department_name, 
      department_tel, department_desc, department_ger, 
      department_type)
    values (#{departmentId,jdbcType=INTEGER}, #{pId,jdbcType=VARCHAR}, #{departmentName,jdbcType=VARCHAR}, 
      #{departmentTel,jdbcType=VARCHAR}, #{departmentDesc,jdbcType=VARCHAR}, #{departmentGer,jdbcType=VARCHAR}, 
      #{departmentType,jdbcType=VARCHAR})
  
  
    insert into department
    
      
        department_id,
      
      
        p_id,
      
      
        department_name,
      
      
        department_tel,
      
      
        department_desc,
      
      
        department_ger,
      
      
        department_type,
      
    
    
      
        #{departmentId,jdbcType=INTEGER},
      
      
        #{pId,jdbcType=VARCHAR},
      
      
        #{departmentName,jdbcType=VARCHAR},
      
      
        #{departmentTel,jdbcType=VARCHAR},
      
      
        #{departmentDesc,jdbcType=VARCHAR},
      
      
        #{departmentGer,jdbcType=VARCHAR},
      
      
        #{departmentType,jdbcType=VARCHAR},
      
    
  
  
    update department
    
      
        p_id = #{pId,jdbcType=VARCHAR},
      
      
        department_name = #{departmentName,jdbcType=VARCHAR},
      
      
        department_tel = #{departmentTel,jdbcType=VARCHAR},
      
      
        department_desc = #{departmentDesc,jdbcType=VARCHAR},
      
      
        department_ger = #{departmentGer,jdbcType=VARCHAR},
      
      
        department_type = #{departmentType,jdbcType=VARCHAR},
      
    
    where department_id = #{departmentId,jdbcType=INTEGER}
  
  
    update department
    set p_id = #{pId,jdbcType=VARCHAR},
      department_name = #{departmentName,jdbcType=VARCHAR},
      department_tel = #{departmentTel,jdbcType=VARCHAR},
      department_desc = #{departmentDesc,jdbcType=VARCHAR},
      department_ger = #{departmentGer,jdbcType=VARCHAR},
      department_type = #{departmentType,jdbcType=VARCHAR}
    where department_id = #{departmentId,jdbcType=INTEGER}
  
  
   
 
  
  
       
 
	
	  

kohgylw.service.impl下建接口      DepartmentService.java

package kohgylw.service.impl;

import kohgylw.model.Department;

public interface DepartmentService {
	//添加部门
	int insertDepartment(Department department);
	//删除部门
	int deleteMember(Department department);
	
	//实现查询所有以及默认分页
	String getDepartmentServicePage(String pageNumber, String departmentType, String departmentName);
	//	修改部门信息
	int updateDepartment(Department department);
	//根据部门名称查询单个信息
	Department selectByDepartmentId(Integer departmentId);

	

}

kohgylw.service.impl下建实现类      DepartmentServiceImpl.java

package kohgylw.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.google.gson.Gson;

import kohgylw.mapper.DepartmentMapper;
import kohgylw.model.Department;
import kohgylw.model.DepartmentPager;

//业务层(调用mapper层)
@Service
public class DepartmentServiceImpl implements DepartmentService {
	

	@Resource
	private DepartmentMapper departmentMapper;

	//添加部门
	public int insertDepartment(Department department) {
		
		return departmentMapper.insert(department);
	}
	//删除部门
	public int deleteMember(Department department) {
		
		return departmentMapper.deleteByPrimaryKey(department.getDepartmentId());
	}
	//实现查询所有以及默认分页
	public String getDepartmentServicePage(String pno, String departmentType, String departmentName) {
		System.out.println("pno"+pno);
		System.out.println("departmentType"+departmentType);
		System.out.println("departmentName"+departmentName);
		//每页记录6条数据
		int pageSize=6;
		//模糊查询赋值
				Map totalMap = new HashMap();
				totalMap.put("departmentType", "%" + departmentType + "%");
				totalMap.put("departmentName", departmentName);
				//求总记录数
				int totalRecords = departmentMapper.queryDepartmentNum(totalMap);
				System.out.println("totalRecords-----1-->"+totalRecords);
				//总页数
				int totalPage = 0;
				Gson gson = new Gson();
				//自定义类
				DepartmentPager departmentPager = new DepartmentPager();
				//给总记录数赋值
				departmentPager.setTotalRecords(totalRecords);
				//求出总页数
				if (totalRecords % pageSize > 0) {
					totalPage = totalRecords / pageSize + 1;
				} else {
					totalPage = totalRecords / pageSize;
				}
				System.out.println("totalPage -----1-->"+totalPage );
				
				departmentPager.setTotal(totalPage);
				//获取当前页
				int n = 1;
				if (pno != null && pno.length() > 0) {
					n = Integer.parseInt(pno);
				}
				
				Map map = new HashMap();
				
				map.put("pno", (n - 1) * pageSize);
				map.put("num", pageSize);
				map.put("departmentType", "%" + departmentType + "%");
				map.put("departmentName", departmentName);
				
				List listdepartments = departmentMapper.querydepartmentPage(map);
				System.out.println(totalRecords + "**********" + pageSize);
				departmentPager.setListDepartments(listdepartments);
				System.out.println("departmentJson=="+gson.toJson(departmentPager));
				return gson.toJson(departmentPager);
	}
	//修改用户信息
	public int updateDepartment(Department department) {
		
		
		return departmentMapper.updateByPrimaryKey(department);
	}
	//根据部门名称查询单个信息
	public Department selectByDepartmentId(Integer departmentId) {
		
		return departmentMapper.selectByDepartmentId(departmentId);
	}
	
	

}

kohgylw.controller下建控制器      DepartmentController.java


package kohgylw.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import kohgylw.model.Department;
import kohgylw.service.impl.DepartmentService;

//控制器层(调用service业务层)
@Controller
@RequestMapping("/Department")
public class DepartmentController {
	
	@Resource
	private DepartmentService departmentService;
	
	//部门添加
	@RequestMapping("/addDepartment.ajax")
	@ResponseBody
	public String addDepartmentr(Department  department){
		  
		int rs = departmentService.insertDepartment(department);
		System.out.println("insert---->"+rs);
		if(rs>0){
			return "dpinsertOK";
		}
		
		return "dpinsertError";
			
	}
	
	//删除部门
		@RequestMapping("/deleteDepartment.ajax")
		@ResponseBody
		public String deleteDepartment(Department department) {
			int rs=departmentService.deleteMember(department);
			
			if(rs>0) {
				
				return "deleteDepartment";
			}
			
			return "deleteDeleteDepartmentError";
		}
	
		// 页面加载实现查询所有以及默认分页
		
		@RequestMapping(value="initDepartmentPage.ajax",produces="text/html;charset=utf-8")
		@ResponseBody
		public String initDepartmentPage(String pageNumber, String departmentType, String departmentName){
			System.out.println("pageNumber==>"+pageNumber);
			System.out.println("DepartmentType==>"+departmentType);
			System.out.println("DepartmentName==>"+departmentName);
			  String departmentJson = departmentService.getDepartmentServicePage(pageNumber, departmentType, departmentName);
			return departmentJson;
		}
		
		//修改部门信息
		@RequestMapping("/updateDepartment.ajax")
		@ResponseBody
		public String updateDepartment(Department department) {
			int rs=departmentService.updateDepartment(department);
			
			System.out.println("rs"+rs);
			if(rs>0) {
				return "updateD";
			}
			
			return "updateError";
		}
		
		//根据部门名称查询单个信息
		@RequestMapping("/queryDepartmentById.do")
		public String queryDepartmentById(HttpServletRequest request,Integer departmentId) {
			
			Department departments=departmentService.selectByDepartmentId(departmentId);
			
			System.out.println("department===="+departments);
			request.setAttribute("department", departments);
			
			return "view/department/department-update";
		}
	

	
}

webapp/view/department下
         department-list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>






部门管理
















	
	
快速查询:
共有数据:
父级部门 部门名称 部门电话 部门描述 主管领导 部门领导 部门操作

department -add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>






添加部门














	
				

department -update.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>




 

部门修改














	
				

你可能感兴趣的:(java)