diff --git a/src/main/java/com/gpnu/crm/mapper/DepartmentMapper.java b/src/main/java/com/gpnu/crm/mapper/DepartmentMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..e187e16dd0fcc658de039cea05448f066a542ffa --- /dev/null +++ b/src/main/java/com/gpnu/crm/mapper/DepartmentMapper.java @@ -0,0 +1,19 @@ +package com.gpnu.crm.mapper; + +import java.util.List; + +import com.gpnu.crm.domain.Department; +import com.gpnu.crm.query.QueryObject; + +public interface DepartmentMapper { + int deleteByPrimaryKey(Long paramLong); + + int insert(Department paramDepartment); + + List selectAll(); + + int updateByPrimaryKey(Department paramDepartment); + + List selectForList(QueryObject paramQueryObject); + +} diff --git a/src/main/java/com/gpnu/crm/service/IDepartmentService.java b/src/main/java/com/gpnu/crm/service/IDepartmentService.java new file mode 100644 index 0000000000000000000000000000000000000000..102da19ccc3db723e45b315bb971cd865bb410be --- /dev/null +++ b/src/main/java/com/gpnu/crm/service/IDepartmentService.java @@ -0,0 +1,17 @@ +package com.gpnu.crm.service; + +import java.util.List; + +import com.github.pagehelper.PageInfo; +import com.gpnu.crm.domain.Department; +import com.gpnu.crm.query.QueryObject; + +public interface IDepartmentService { + void saveOrUpdate(Department paramDepartment); + + void delete(Long paramLong); + + List list(); + + PageInfo query(QueryObject paramQueryObject); +} diff --git a/src/main/java/com/gpnu/crm/service/impl/DepartmentServiceImpl.java b/src/main/java/com/gpnu/crm/service/impl/DepartmentServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..ac39a6243a8a31ca661cbd57b3c18a0f6076f669 --- /dev/null +++ b/src/main/java/com/gpnu/crm/service/impl/DepartmentServiceImpl.java @@ -0,0 +1,46 @@ +package com.gpnu.crm.service.impl; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.gpnu.crm.domain.Department; +import com.gpnu.crm.mapper.DepartmentMapper; +import com.gpnu.crm.query.QueryObject; +import com.gpnu.crm.service.IDepartmentService; + +@Service +public class DepartmentServiceImpl implements IDepartmentService { + + @Autowired + private DepartmentMapper departmentMapper; + + public DepartmentServiceImpl() { + } + + public void saveOrUpdate(Department entity) { + if (entity.getId() == null) { + departmentMapper.insert(entity); + } else { + departmentMapper.updateByPrimaryKey(entity); + } + } + + public void delete(Long id) { + departmentMapper.deleteByPrimaryKey(id); + } + + public List list() { + return departmentMapper.selectAll(); + } + + public PageInfo query(QueryObject qo) { + PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize()); + List list = departmentMapper.selectForList(qo); + return new PageInfo(list); + } + +} diff --git a/src/main/java/com/gpnu/crm/web/controller/DepartmentController.java b/src/main/java/com/gpnu/crm/web/controller/DepartmentController.java new file mode 100644 index 0000000000000000000000000000000000000000..6e86b2e4ed62fc1718e0a1ce3f461e9b7878527d --- /dev/null +++ b/src/main/java/com/gpnu/crm/web/controller/DepartmentController.java @@ -0,0 +1,40 @@ +package com.gpnu.crm.web.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.github.pagehelper.PageInfo; +import com.gpnu.crm.domain.Department; +import com.gpnu.crm.query.QueryObject; +import com.gpnu.crm.service.IDepartmentService; +import com.gpnu.crm.util.JSONResult; + +@Controller +@RequestMapping("/department") +public class DepartmentController { + @Autowired + private IDepartmentService departmentService; + + @RequestMapping("/list") + public String list(@ModelAttribute("qo")QueryObject qo, Model model) { + PageInfo info = departmentService.query(qo); + model.addAttribute("pageInfo", info); + return "department/list"; + } + + @RequestMapping("/saveOrUpdate") + public String saveOrUpdate(Department entity) { + departmentService.saveOrUpdate(entity); + return "redirect:/department/list.do"; + } + + @RequestMapping("/delete") + public String delete(Long id) { + departmentService.delete(id); + return "redirect:/department/list.do"; + } +} diff --git a/src/main/java/com/gpnu/crm/web/controller/EmployeeController.java b/src/main/java/com/gpnu/crm/web/controller/EmployeeController.java index 47ea4bb80274f7f73b658da8046965f0a53bbdfa..3c53f2326d69302ce782494652b8929de3d9488e 100644 --- a/src/main/java/com/gpnu/crm/web/controller/EmployeeController.java +++ b/src/main/java/com/gpnu/crm/web/controller/EmployeeController.java @@ -10,8 +10,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.github.pagehelper.PageInfo; +import com.gpnu.crm.domain.Department; import com.gpnu.crm.domain.Employee; import com.gpnu.crm.query.QueryObject; +import com.gpnu.crm.service.IDepartmentService; import com.gpnu.crm.service.IEmployeeService; @@ -23,14 +25,19 @@ import com.gpnu.crm.service.IEmployeeService; public class EmployeeController { @Autowired private IEmployeeService employeeService; + + @Autowired + private IDepartmentService departmentService; //访问到这个方法,localhost:8080/employee/list.do @RequestMapping("/list") public String list(@ModelAttribute("qo") QueryObject qo, Model model) { //model相当于作用域request PageInfo info = employeeService.list(qo); + List departments = departmentService.list(); //访问模型中 model.addAttribute("pageInfo", info); + model.addAttribute("depts", departments); return "employee/list"; //跳转到员工列表界面作数据展示 } @@ -44,8 +51,9 @@ public class EmployeeController { public String input(Model model,Long id){ //查询需要编辑的数据 Employee e = employeeService.get(id); + List departments = departmentService.list(); model.addAttribute("e",e); - + model.addAttribute("depts", departments); return "employee/input"; } diff --git a/src/main/resources/com/gpnu/crm/mapper/DepartmentMapper.xml b/src/main/resources/com/gpnu/crm/mapper/DepartmentMapper.xml new file mode 100644 index 0000000000000000000000000000000000000000..ee826b3ac941701053f3ebf05019d046c47b7e5c --- /dev/null +++ b/src/main/resources/com/gpnu/crm/mapper/DepartmentMapper.xml @@ -0,0 +1,32 @@ + + + + + + delete from department + where id = #{id} + + + + insert into department (name, sn) + values (#{name}, #{sn}) + + + + update department + set name = #{name}, + sn = #{sn} + where id = #{id} + + + + + + + \ No newline at end of file diff --git a/src/main/resources/com/gpnu/crm/mapper/EmployeeMapper.xml b/src/main/resources/com/gpnu/crm/mapper/EmployeeMapper.xml index 070b9f5c2d40f3d5607d7532d22d7257676ffbac..1e4d699b79bf79291ccf88ae778de88e9aff71f2 100644 --- a/src/main/resources/com/gpnu/crm/mapper/EmployeeMapper.xml +++ b/src/main/resources/com/gpnu/crm/mapper/EmployeeMapper.xml @@ -5,13 +5,30 @@ - + select e.id, e.name, e.email, e.age, d.id dept_id, d.name dept_name + from employee e + join department d on e.dept_id = d.id - - AND (name LIKE concat('%',#{keyword},'%') OR email LIKE + and (e.name LIKE concat('%',#{keyword},'%') OR e.email + LIKE concat('%',#{keyword},'%')) @@ -81,7 +98,8 @@ diff --git a/src/main/resources/db.properties b/src/main/resources/db.properties index e9c8a02aab2d0429671a56e808aa4102ac59783c..1dff8cbf0035c4e60710c92750ee4c2110f0eda2 100644 --- a/src/main/resources/db.properties +++ b/src/main/resources/db.properties @@ -1,4 +1,4 @@ -jdbc.driverClassName=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://193.112.42.230:3306/crm_test?useUnicode=true&characterEncoding=utf8&useSSL=false -jdbc.username=crm_test -jdbc.password=wq+549654065 \ No newline at end of file +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/crm_test?useUnicode=true&characterEncoding=utf8&useSSL=false +jdbc.username=root +jdbc.password=123456 \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/common/page.jsp b/src/main/webapp/WEB-INF/views/common/page.jsp index 7458f6b8611dd1b32ebf285abf79d38c5071cb68..c22927605373cacb96a7e7b1eadc8d1ff76f83d9 100644 --- a/src/main/webapp/WEB-INF/views/common/page.jsp +++ b/src/main/webapp/WEB-INF/views/common/page.jsp @@ -1,8 +1,8 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page contentType="text/html;charset=UTF-8" language="java"%>
- +
+ diff --git a/src/main/webapp/WEB-INF/views/department/list.jsp b/src/main/webapp/WEB-INF/views/department/list.jsp new file mode 100644 index 0000000000000000000000000000000000000000..ca3649340a8cd805ac64e1c8bd60ed536b45658d --- /dev/null +++ b/src/main/webapp/WEB-INF/views/department/list.jsp @@ -0,0 +1,120 @@ +<%@ page language="java" contentType="text/html;charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> + + + +<%@ include file="../common/header.jsp"%> + + + +
+ <%@ include file="../common/top.jsp"%> + +
+
+ + <%@ include file="../common/menu.jsp"%> +
+
+
+
+

部门管理

+
+
+ +
+ + 添加 + +
+ + + + + + + + + + + + + + + + +
编号部门名称部门编码操作
${entity.id}${entity.name}${entity.sn} 编辑 + 删除 +
+ <%@ include file="../common/page.jsp"%> +
+
+
+ + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/employee/input.jsp b/src/main/webapp/WEB-INF/views/employee/input.jsp index 82b5be5e914380c3bf52a41e1d30a2ad5e013828..9adad4a32997f666ca3f620886548b0abc374bfc 100644 --- a/src/main/webapp/WEB-INF/views/employee/input.jsp +++ b/src/main/webapp/WEB-INF/views/employee/input.jsp @@ -1,60 +1,65 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ page contentType="text/html;charset=UTF-8" language="java"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> - <%@ include file="../common/header.jsp" %> +<%@ include file="../common/header.jsp"%> -
- <%@ include file="../common/top.jsp" %> +
+ <%@ include file="../common/top.jsp"%> -
-
- - <%@ include file="../common/menu.jsp" %> -
-
-
-
-

员工编辑

-
-
-
-
- -
- -
- -
-
+
+
+ + <%@ include file="../common/menu.jsp"%> +
+
+
+
+

员工编辑

+
+
+
+ + +
+ +
+ +
+
-
- -
- -
-
+
+ +
+ +
+
-
- -
- -
-
- -
-
- - -
-
- -
-
-
-
+
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+
+
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/employee/list.jsp b/src/main/webapp/WEB-INF/views/employee/list.jsp index fd6eafe9bd6412f8387a0317eba4892abcc7051c..94ba2c536e15276dca34d85865b68f3821fd7650 100644 --- a/src/main/webapp/WEB-INF/views/employee/list.jsp +++ b/src/main/webapp/WEB-INF/views/employee/list.jsp @@ -1,79 +1,79 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> +<%@ page contentType="text/html;charset=UTF-8" language="java"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%> - <%@ include file="../common/header.jsp" %> +<%@ include file="../common/header.jsp"%> -
- <%@ include file="../common/top.jsp" %> +
+ <%@ include file="../common/top.jsp"%> -
-
- - <%@ include file="../common/menu.jsp" %> -
-
-
-
-

员工管理

-
-
-
- -
- - -
- - - - 添加 - -
+
+
+ + <%@ include file="../common/menu.jsp"%> +
+
+
+
+

员工管理

+
+
+
+ +
+ +
- - - - - - - - - - - - - - - - - - -
编号名称email年龄操作
${entity.id}${entity.name}${entity.email}${entity.age} - - - 编辑 - - - - - 删除 - - -
+ + 添加 + +
- <%@ include file="../common/page.jsp" %> -
-
-
+ + + + + + + + + + + + + + + + + + + + +
编号名称email年龄部门操作
${entity.id}${entity.name}${entity.email}${entity.age}${entity.dept.name} + 编辑 + + + 删除 + +
+ + <%@ include file="../common/page.jsp"%> +
+
+
\ No newline at end of file