package com.dbnt.kcgfilemanager.controller; import com.dbnt.kcgfilemanager.model.CommonCode; import com.dbnt.kcgfilemanager.service.CommonCodeService; import lombok.RequiredArgsConstructor; import org.json.simple.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.net.http.HttpResponse; import java.util.List; @Controller @RequiredArgsConstructor @RequestMapping("/admin") public class adminController { private final CommonCodeService commonCodeService; /** * 회원가입 페이지 이동 * @return */ @GetMapping("/signup") public String goSignup() { return "login/signup"; } /** * Admin 페이지 이동 * @return */ @GetMapping("/main") public String goAdmin() { return "admin/main"; } @GetMapping("/userMgt") public String userMgt() { return "admin/userMgt"; } @GetMapping("/modifyRequest") public String modifyRequest() { return "admin/modifyRequest"; } @GetMapping("/codeMgt") public ModelAndView codeMgt(CommonCode commonCode) { ModelAndView mav = new ModelAndView("admin/codeMgt"); mav.addObject("categoryList", commonCodeService.selectCommonCodeCategory(commonCode)); return mav; } @GetMapping("/codeValue") public ModelAndView codeValue(CommonCode commonCode) { ModelAndView mav = new ModelAndView("admin/codeValue"); mav.addObject("valueList", commonCodeService.selectCommonCodeValue(commonCode)); return mav; } @PutMapping("/insertCommonCode") public void insertCommonCode(HttpServletResponse res, CommonCode commonCode){ res.setCharacterEncoding("UTF-8"); res.setContentType("text/html; charset=UTF-8"); PrintWriter writerJson = null; JSONObject jsonObject = new JSONObject(); commonCodeService.insertCommonCode(commonCode); jsonObject.put("codeSq", commonCode.getCodeSq()); jsonObject.put("category", commonCode.getCategory()); jsonObject.put("value", commonCode.getValue()); try { writerJson = res.getWriter(); } catch (IOException e) { e.printStackTrace(); } writerJson.print(jsonObject); } @PutMapping("/updateCommonCode") public void updateCommonCode(HttpServletResponse res, List commonCodeList){ res.setCharacterEncoding("UTF-8"); res.setContentType("text/html; charset=UTF-8"); PrintWriter writerJson = null; JSONObject jsonObject = new JSONObject(); System.out.println(commonCodeList.size()); // jsonObject.put("codeSq", commonCode.getCodeSq()); try { writerJson = res.getWriter(); } catch (IOException e) { e.printStackTrace(); } writerJson.print(jsonObject); } }