Skip to content

Commit b914e3f

Browse files
committed
finish dept fun
1 parent b33c44f commit b914e3f

22 files changed

Lines changed: 574 additions & 9 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.giit.www.college.controller;
2+
3+
import com.giit.www.college.service.DeptBiz;
4+
import com.giit.www.entity.Dept;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.ui.Model;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
9+
import javax.annotation.Resource;
10+
11+
/**
12+
* Created by c0de8ug on 16-2-10.
13+
*/
14+
15+
@Controller
16+
@RequestMapping("dept.do")
17+
public class DeptController {
18+
19+
@Resource(name = "deptBizImpl")
20+
private DeptBiz deptBiz;
21+
22+
@RequestMapping("findAll")
23+
public String findAll(Model m) {
24+
m.addAttribute("departments", deptBiz.findAll());
25+
return "/college/dept";
26+
}
27+
28+
@RequestMapping("add")
29+
public String add(String deptName) {
30+
deptBiz.add(deptName);
31+
return "redirect:/dept.do/findAll";
32+
}
33+
34+
@RequestMapping("update")
35+
public String update(Dept dept) {
36+
deptBiz.update(dept);
37+
return "redirect:/dept.do/findAll";
38+
}
39+
40+
@RequestMapping("delete")
41+
public String delete(int deptId) {
42+
deptBiz.delete(deptId);
43+
return "redirect:/dept.do/findAll";
44+
}
45+
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE mapper
3+
PUBLIC "-//mybatis.org//DTD mapper 3.0//EN"
4+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5+
6+
7+
<mapper namespace="com.giit.www.college.dao.ClassDao">
8+
9+
<resultMap id="class_map" type="Class">
10+
<id property="classId" column="class_id"/>
11+
<result property="className" column="dept_name"/>
12+
</resultMap>
13+
14+
<select id="findAll" resultMap="dept_map">
15+
SELECT * FROM department
16+
</select>
17+
18+
<select id="findById" parameterType="int" resultMap="class_map">
19+
SELECT * FROM department WHERE dept_id = #{value}
20+
</select>
21+
22+
<select id="findByName" parameterType="String" resultMap="class_map">
23+
SELECT * FROM department WHERE dept_name = #{value}
24+
</select>
25+
26+
<update id="update" parameterType="Class">
27+
UPDATE user SET dept_name = #{deptName} WHERE dept_id = #{deptId}
28+
</update>
29+
30+
<insert id="add" parameterType="String">
31+
INSERT INTO department(dept_name) VALUES(#{value})
32+
</insert>
33+
34+
<delete id="delete" parameterType="int">
35+
DELETE FROM department WHERE dept_id = #{value}
36+
</delete>
37+
</mapper>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.giit.www.college.dao;
2+
3+
/**
4+
* Created by c0de8ug on 16-2-11.
5+
*/
6+
public interface ClassDao {
7+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.giit.www.college.dao;
2+
3+
import com.giit.www.entity.Dept;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by c0de8ug on 16-2-10.
9+
*/
10+
public interface DeptDao {
11+
public List<Dept> findAll();
12+
13+
public void add(String deptName);
14+
15+
public void update(Dept dept);
16+
17+
public void delete(int deptId);
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE mapper
3+
PUBLIC "-//mybatis.org//DTD mapper 3.0//EN"
4+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5+
6+
7+
<mapper namespace="com.giit.www.college.dao.DeptDao">
8+
9+
<resultMap id="dept_map" type="Dept">
10+
<id property="deptId" column="dept_id"/>
11+
<result property="deptName" column="dept_name"/>
12+
</resultMap>
13+
14+
<select id="findAll" resultMap="dept_map">
15+
SELECT * FROM department
16+
</select>
17+
18+
<select id="findById" parameterType="int" resultMap="dept_map">
19+
SELECT * FROM department WHERE dept_id = #{value}
20+
</select>
21+
22+
<select id="findByName" parameterType="String" resultMap="dept_map">
23+
SELECT * FROM department WHERE dept_name = #{value}
24+
</select>
25+
26+
<update id="update" parameterType="Dept">
27+
UPDATE department SET dept_name = #{deptName} WHERE dept_id = #{deptId}
28+
</update>
29+
30+
<insert id="add" parameterType="String">
31+
INSERT INTO department(dept_name) VALUES(#{value})
32+
</insert>
33+
34+
<delete id="delete" parameterType="int">
35+
DELETE FROM department WHERE dept_id = #{value}
36+
</delete>
37+
</mapper>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.giit.www.college.service;
2+
3+
import com.giit.www.entity.Dept;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by c0de8ug on 16-2-11.
9+
*/
10+
public interface DeptBiz {
11+
public List<Dept> findAll();
12+
13+
public void add(String deptName);
14+
15+
public void update(Dept dept);
16+
17+
public void delete(int deptId);
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.giit.www.college.service.impl;
2+
3+
import com.giit.www.college.dao.DeptDao;
4+
import com.giit.www.college.service.DeptBiz;
5+
import com.giit.www.entity.Dept;
6+
import org.springframework.stereotype.Service;
7+
8+
import javax.annotation.Resource;
9+
import java.util.List;
10+
11+
/**
12+
* Created by c0de8ug on 16-2-11.
13+
*/
14+
15+
@Service
16+
public class DeptBizImpl implements DeptBiz {
17+
@Resource
18+
private DeptDao deptDao;
19+
20+
public List<Dept> findAll() {
21+
return deptDao.findAll();
22+
}
23+
24+
public void add(String deptName) {
25+
deptDao.add(deptName);
26+
}
27+
28+
public void update(Dept dept) {
29+
deptDao.update(dept);
30+
}
31+
32+
public void delete(int deptId) {
33+
deptDao.delete(deptId);
34+
}
35+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Created by c0de8ug on 16-2-9.
55
*/
6-
public class Department {
6+
public class Dept {
77
int deptId;
88
String deptName;
99

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package com.giit.www.system.controller;
22

3+
import com.giit.www.entity.User;
34
import com.giit.www.system.service.UserBiz;
45
import org.springframework.stereotype.Controller;
56
import org.springframework.ui.Model;
7+
import org.springframework.ui.ModelMap;
68
import org.springframework.web.bind.annotation.RequestMapping;
79

810
import javax.annotation.Resource;
11+
import javax.servlet.http.HttpServletRequest;
12+
import javax.servlet.http.HttpServletResponse;
913

1014
/**
1115
* Created by c0de8ug on 16-2-9.
1216
*/
1317

1418
@Controller
15-
@RequestMapping("user")
19+
@RequestMapping("user.do")
1620
public class UserController {
1721

1822
@Resource(name = "userBizImpl")
@@ -21,7 +25,32 @@ public class UserController {
2125
@RequestMapping("findAll")
2226
public String findAll(Model m) {
2327
m.addAttribute("userList", userBiz.findAll());
24-
return "system/user";
28+
return "system/userinfo/user";
29+
}
30+
31+
@RequestMapping("findById")
32+
public String findById(String id, Model m) {
33+
//todo 这里要做非空判断
34+
m.addAttribute("user", userBiz.findById(id));
35+
return "system/userinfo/user_update";
36+
}
37+
38+
@RequestMapping("update")
39+
public String update(User user) {
40+
userBiz.update(user);
41+
return "redirect:/user.do/findAll";
42+
}
43+
44+
@RequestMapping("add")
45+
public String add(User user) {
46+
userBiz.add(user);
47+
return "redirect:/user.do/findAll";
48+
}
49+
50+
@RequestMapping("delete")
51+
public String delete(String id) {
52+
userBiz.delete(id);
53+
return "redirect:/user.do/findAll";
2554
}
2655

2756
}

src/com/giit/www/system/dao/UserDao.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@
99
*/
1010
public interface UserDao {
1111
public List<User> findAll();
12+
13+
public User findById(String id);
14+
15+
public void update(User user);
16+
17+
public void add(User user);
18+
19+
public void delete(String id);
1220
}

0 commit comments

Comments
 (0)