-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmpController.java
More file actions
62 lines (50 loc) · 1.74 KB
/
EmpController.java
File metadata and controls
62 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.spring.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;
import com.spring.dto.Dept;
import com.spring.dto.Emp;
import com.spring.service.EmpService;
@Controller
public class EmpController {
@Autowired
EmpService eservice;
@GetMapping("/emp/form")
public String form() {
return "emp/form";
}
@PostMapping("/emp/search")
public String searchEmp(@ModelAttribute("ename") String ename, @ModelAttribute("job")String job, Model m) {
List<Emp> elist = eservice.searchEmp(ename,job);
m.addAttribute("elist",elist);
return "emp/result";
}
@GetMapping("/emp/option")
public String showOption(Model m){
List<Dept> dlist = eservice.showOption(); // 부서 정보 리스트
m.addAttribute("deptinfo",dlist);
return "emp/option";
}
@GetMapping("/emp/select1")
@ResponseBody
public String showEmp(@RequestParam("deptno") int deptno) {
List<Emp> elist = eservice.showEmp(deptno);
// 해당 부서번호의 emp리스트를 gson으로 전달
Gson gson = new Gson();
return gson.toJson(elist);
}
@GetMapping("/emp/select1/select2")
@ResponseBody
public String selectEmp(@RequestParam("ename") String ename) {
Emp e = eservice.selectEmp(ename);
Gson gson = new Gson();
return gson.toJson(e);
}
}