|
22 | 22 | @Controller |
23 | 23 | public class CompanyController { |
24 | 24 |
|
25 | | - Map<Long, Company> companyMap = new HashMap<>(); |
| 25 | + Map<Long, Company> companyMap = new HashMap<>(); |
26 | 26 |
|
27 | | - @RequestMapping(value = "/company", method = RequestMethod.GET) |
28 | | - public ModelAndView showForm() { |
29 | | - return new ModelAndView("companyHome", "company", new Company()); |
30 | | - } |
| 27 | + @RequestMapping(value = "/company", method = RequestMethod.GET) |
| 28 | + public ModelAndView showForm() { |
| 29 | + return new ModelAndView("companyHome", "company", new Company()); |
| 30 | + } |
31 | 31 |
|
32 | | - @RequestMapping(value = "/company/{Id}", produces = { "application/json", |
33 | | - "application/xml" }, method = RequestMethod.GET) |
34 | | - public @ResponseBody Company getCompanyById(@PathVariable final long Id) { |
35 | | - return companyMap.get(Id); |
36 | | - } |
| 32 | + @RequestMapping(value = "/company/{Id}", produces = { "application/json", "application/xml" }, method = RequestMethod.GET) |
| 33 | + public @ResponseBody Company getCompanyById(@PathVariable final long Id) { |
| 34 | + return companyMap.get(Id); |
| 35 | + } |
37 | 36 |
|
38 | | - @RequestMapping(value = "/addCompany", method = RequestMethod.POST) |
39 | | - public String submit(@ModelAttribute("company") final Company company, |
40 | | - final BindingResult result, final ModelMap model) { |
41 | | - if (result.hasErrors()) { |
42 | | - return "error"; |
43 | | - } |
44 | | - model.addAttribute("name", company.getName()); |
45 | | - model.addAttribute("id", company.getId()); |
| 37 | + @RequestMapping(value = "/addCompany", method = RequestMethod.POST) |
| 38 | + public String submit(@ModelAttribute("company") final Company company, final BindingResult result, final ModelMap model) { |
| 39 | + if (result.hasErrors()) { |
| 40 | + return "error"; |
| 41 | + } |
| 42 | + model.addAttribute("name", company.getName()); |
| 43 | + model.addAttribute("id", company.getId()); |
46 | 44 |
|
47 | | - companyMap.put(company.getId(), company); |
| 45 | + companyMap.put(company.getId(), company); |
48 | 46 |
|
49 | | - return "companyView"; |
50 | | - } |
| 47 | + return "companyView"; |
| 48 | + } |
51 | 49 |
|
52 | | - @RequestMapping(value = "/companyEmployee/{company}/employeeData/{employee}", method = RequestMethod.GET) |
53 | | - @ResponseBody |
54 | | - public ResponseEntity<Map<String, String>> getEmployeeDataFromCompany( |
55 | | - @MatrixVariable(pathVar = "employee") final Map<String, String> matrixVars) { |
56 | | - return new ResponseEntity<>(matrixVars, HttpStatus.OK); |
57 | | - } |
| 50 | + @RequestMapping(value = "/companyEmployee/{company}/employeeData/{employee}", method = RequestMethod.GET) |
| 51 | + @ResponseBody |
| 52 | + public ResponseEntity<Map<String, String>> getEmployeeDataFromCompany(@MatrixVariable(pathVar = "employee") final Map<String, String> matrixVars) { |
| 53 | + return new ResponseEntity<>(matrixVars, HttpStatus.OK); |
| 54 | + } |
58 | 55 |
|
59 | | - @RequestMapping(value = "/companyData/{company}/employeeData/{employee}", method = RequestMethod.GET) |
60 | | - @ResponseBody |
61 | | - public ResponseEntity<Map<String, String>> getCompanyName( |
62 | | - @MatrixVariable(value = "name", pathVar = "company") final String name) { |
63 | | - final Map<String, String> result = new HashMap<String, String>(); |
64 | | - result.put("name", name); |
65 | | - return new ResponseEntity<>(result, HttpStatus.OK); |
66 | | - } |
| 56 | + @RequestMapping(value = "/companyData/{company}/employeeData/{employee}", method = RequestMethod.GET) |
| 57 | + @ResponseBody |
| 58 | + public ResponseEntity<Map<String, String>> getCompanyName(@MatrixVariable(value = "name", pathVar = "company") final String name) { |
| 59 | + final Map<String, String> result = new HashMap<String, String>(); |
| 60 | + result.put("name", name); |
| 61 | + return new ResponseEntity<>(result, HttpStatus.OK); |
| 62 | + } |
67 | 63 |
|
68 | | - @RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE) |
69 | | - @ResponseBody |
70 | | - public Company getCompanyResponseBody() { |
71 | | - final Company company = new Company(2, "ABC"); |
72 | | - return company; |
73 | | - } |
| 64 | + @RequestMapping(value = "/companyResponseBody", produces = MediaType.APPLICATION_JSON_VALUE) |
| 65 | + @ResponseBody |
| 66 | + public Company getCompanyResponseBody() { |
| 67 | + final Company company = new Company(2, "ABC"); |
| 68 | + return company; |
| 69 | + } |
74 | 70 |
|
75 | | - @RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE) |
76 | | - public ResponseEntity<Company> getCompanyResponseEntity() { |
77 | | - final Company company = new Company(3, "123"); |
78 | | - return new ResponseEntity<Company>(company, HttpStatus.OK); |
79 | | - } |
| 71 | + @RequestMapping(value = "/companyResponseEntity", produces = MediaType.APPLICATION_JSON_VALUE) |
| 72 | + public ResponseEntity<Company> getCompanyResponseEntity() { |
| 73 | + final Company company = new Company(3, "123"); |
| 74 | + return new ResponseEntity<Company>(company, HttpStatus.OK); |
| 75 | + } |
80 | 76 | } |
0 commit comments