중간저장.

master
강석 최 2021-12-02 18:10:30 +09:00
parent 0a10167487
commit 3bf841d809
12 changed files with 115 additions and 105 deletions

View File

@ -27,8 +27,6 @@ dependencies {
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4' implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.5.3' implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.5.3'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'

View File

@ -4,27 +4,32 @@ import com.dbnt.kcgfilemanager.model.UserInfo;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.security.Principal; import java.security.Principal;
@Controller @RestController
public class BaseController { public class BaseController {
@GetMapping("/") @GetMapping("/")
public String loginCheck(Principal principal) { public ModelAndView loginCheck(Principal principal) {
ModelAndView mav = null;
if(principal == null){ if(principal == null){
return "redirect:/user/login"; mav = new ModelAndView("redirect:/user/login");
}else{ }else{
if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){ if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){
return "redirect:/admin/main"; mav = new ModelAndView("redirect:/admin/main");
}else{ }else{
return "redirect:/user/main"; mav = new ModelAndView("redirect:/user/main");
} }
} }
return mav;
} }
@GetMapping("/user/main") @GetMapping("/user/main")
public String main() { public ModelAndView main() {
return "main"; ModelAndView mav = new ModelAndView("main");
return mav;
} }
} }

View File

@ -7,8 +7,10 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@Controller @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserInfoController { public class UserInfoController {
@ -16,34 +18,39 @@ public class UserInfoController {
/** * 로그인 페이지 이동 * @return */ /** * 로그인 페이지 이동 * @return */
@GetMapping("/user/login") @GetMapping("/user/login")
public String goLogin() { public ModelAndView goLogin() {
return "login"; ModelAndView mav = new ModelAndView("login");
return mav;
} }
/** * 로그인 에러 * @param model * @return */ /** * 로그인 에러 * @param model * @return */
@GetMapping("/login-error") @GetMapping("/login-error")
public String loginError(Model model) { public ModelAndView loginError() {
model.addAttribute("loginError", true); ModelAndView mav = new ModelAndView("/login");
return "/login"; mav.addObject("loginError", true);
return mav;
} }
/** * 회원가입 처리 * @param memberDto * @return */ /** * 회원가입 처리 * @param memberDto * @return */
@PostMapping("/signup") @PostMapping("/signup")
public String signup(UserInfo userInfo) { public ModelAndView signup(UserInfo userInfo) {
ModelAndView mav = new ModelAndView("redirect:/user/login");
userInfoService.signup(userInfo); userInfoService.signup(userInfo);
return "redirect:/user/login"; return mav;
} }
/** * 접근 거부 페이지 이동 * @return */ /** * 접근 거부 페이지 이동 * @return */
@GetMapping("/denied") @GetMapping("/denied")
public String doDenied() { public ModelAndView doDenied() {
return "login/denied"; ModelAndView mav = new ModelAndView("login/denied");
return mav;
} }
/** * 내 정보 페이지 이동 * @return */ /** * 내 정보 페이지 이동 * @return */
@GetMapping("/info") @GetMapping("/info")
public String goMyInfo() { public ModelAndView goMyInfo() {
return "login/myinfo"; ModelAndView mav = new ModelAndView("login/myinfo");
return mav;
} }
} }

View File

@ -3,44 +3,40 @@ package com.dbnt.kcgfilemanager.controller;
import com.dbnt.kcgfilemanager.model.CommonCode; import com.dbnt.kcgfilemanager.model.CommonCode;
import com.dbnt.kcgfilemanager.service.CommonCodeService; import com.dbnt.kcgfilemanager.service.CommonCodeService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.json.simple.JSONObject; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.util.ArrayList;
import java.io.PrintWriter; import java.util.HashMap;
import java.net.http.HttpResponse;
import java.util.List; import java.util.List;
import java.util.Map;
@Controller @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
@RequestMapping("/admin") @RequestMapping("/admin")
public class adminController { public class adminController {
private final CommonCodeService commonCodeService; private final CommonCodeService commonCodeService;
/** * 회원가입 페이지 이동 * @return */
@GetMapping("/signup")
public String goSignup() {
return "login/signup";
}
/** * Admin 페이지 이동 * @return */
@GetMapping("/main") @GetMapping("/main")
public String goAdmin() { public ModelAndView goAdmin() {
return "admin/main"; ModelAndView mav = new ModelAndView("admin/main");
return mav;
} }
@GetMapping("/userMgt") @GetMapping("/userMgt")
public String userMgt() { public ModelAndView userMgt() {
return "admin/userMgt"; ModelAndView mav = new ModelAndView("admin/userMgt");
return mav;
} }
@GetMapping("/modifyRequest") @GetMapping("/modifyRequest")
public String modifyRequest() { public ModelAndView modifyRequest() {
return "admin/modifyRequest"; ModelAndView mav = new ModelAndView("admin/modifyRequest");
return mav;
} }
@GetMapping("/codeMgt") @GetMapping("/codeMgt")
@ -57,36 +53,23 @@ public class adminController {
return mav; return mav;
} }
@PutMapping("/insertCommonCode") @PutMapping("/insertCode")
public void insertCommonCode(HttpServletResponse res, CommonCode commonCode){ public CommonCode insertCommonCode(CommonCode commonCode){
res.setCharacterEncoding("UTF-8");
res.setContentType("text/html; charset=UTF-8");
PrintWriter writerJson = null;
JSONObject jsonObject = new JSONObject();
commonCodeService.insertCommonCode(commonCode); commonCodeService.insertCommonCode(commonCode);
jsonObject.put("codeSq", commonCode.getCodeSq()); return commonCode;
jsonObject.put("category", commonCode.getCategory());
jsonObject.put("value", commonCode.getValue());
try {
writerJson = res.getWriter();
} catch (IOException e) {
e.printStackTrace();
} }
writerJson.print(jsonObject);
} @PostMapping(value = "/deleteCode")
@PutMapping("/updateCommonCode") @ResponseBody
public void updateCommonCode(HttpServletResponse res, List<CommonCode> commonCodeList){ public int deleteCommonCode(
res.setCharacterEncoding("UTF-8"); // @RequestBody HashMap<String, Object> map
res.setContentType("text/html; charset=UTF-8"); // @RequestBody CommonCode code
PrintWriter writerJson = null; @RequestBody List<CommonCode> codeList
JSONObject jsonObject = new JSONObject(); ) {
System.out.println(commonCodeList.size()); // return map.size();
// jsonObject.put("codeSq", commonCode.getCodeSq()); // return code.getCodeSq();
try { commonCodeService.updateCommonCode(codeList);
writerJson = res.getWriter(); return codeList.size();
} catch (IOException e) {
e.printStackTrace();
}
writerJson.print(jsonObject);
} }
} }

View File

@ -1,8 +1,6 @@
package com.dbnt.kcgfilemanager.model; package com.dbnt.kcgfilemanager.model;
import lombok.Getter; import lombok.*;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
@ -10,19 +8,19 @@ import javax.persistence.*;
@Getter @Getter
@Setter @Setter
@Entity
@NoArgsConstructor @NoArgsConstructor
@DynamicInsert @DynamicInsert
@DynamicUpdate @DynamicUpdate
@Entity
@Table(name = "COMMON_CODE") @Table(name = "COMMON_CODE")
public class CommonCode { public class CommonCode {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CODE_SQ") @Column(name = "CODE_SQ")
private Integer codeSq; private Integer codeSq;
@Column(name = "CATEGORY") @Column(name = "CATEGORY", nullable = false)
private String category; private String category;
@Column(name = "VALUE") @Column(name = "VALUE", nullable = false)
private String value; private String value;
@Column(name = "DESCRIPTION") @Column(name = "DESCRIPTION")
private String description; private String description;

View File

@ -15,10 +15,10 @@ import java.util.Set;
@Getter @Getter
@Setter @Setter
@Entity
@NoArgsConstructor @NoArgsConstructor
@DynamicInsert @DynamicInsert
@DynamicUpdate @DynamicUpdate
@Entity
@Table(name = "USER_INFO") @Table(name = "USER_INFO")
public class UserInfo implements UserDetails{ public class UserInfo implements UserDetails{
@Id @Id

View File

@ -3,7 +3,10 @@ package com.dbnt.kcgfilemanager.repository;
import com.dbnt.kcgfilemanager.model.CommonCode; import com.dbnt.kcgfilemanager.model.CommonCode;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CommonCodeRepository extends JpaRepository<CommonCode, Integer> { public interface CommonCodeRepository extends JpaRepository<CommonCode, Integer> {
List<CommonCode> findByCategory(String category);
} }

View File

@ -26,9 +26,13 @@ public class CommonCodeService {
return commonCodeMapper.selectCommonCodeCategory(commonCode); return commonCodeMapper.selectCommonCodeCategory(commonCode);
} }
public List<CommonCode> selectCommonCodeValue(CommonCode commonCode) { public List<CommonCode> selectCommonCodeValue(CommonCode commonCode) {
return commonCodeMapper.selectCommonCodeValue(commonCode); return commonCodeRepository.findByCategory(commonCode.getCategory());
} }
public void insertCommonCode(CommonCode commonCode) { public void insertCommonCode(CommonCode commonCode) {
commonCodeRepository.save(commonCode); commonCodeRepository.save(commonCode);
} }
public void updateCommonCode(List<CommonCode> codeList) {
commonCodeRepository.saveAll(codeList);
}
} }

View File

@ -46,12 +46,11 @@ $(document).on('click', '#saveBtn', function (){
if(confirm("저장하시겠습니까?")){ if(confirm("저장하시겠습니까?")){
const formData = new FormData($("#commonCodeForm")[0]); const formData = new FormData($("#commonCodeForm")[0]);
$.ajax({ $.ajax({
processData: false,
contentType: false,
url : "/admin/insertCommonCode",
type : 'PUT', type : 'PUT',
data : formData, data : formData,
dataType: 'json', url : "/admin/insertCode",
processData: false,
contentType: false,
success : function(data) { success : function(data) {
alert("저장되었습니다.") alert("저장되었습니다.")
$("#closeModalBtn").click(); $("#closeModalBtn").click();
@ -65,15 +64,21 @@ $(document).on('click', '#saveBtn', function (){
} }
}) })
$(document).on('click', '#deleteCommonCodeBtn', function (){ $(document).on('click', '#deleteCommonCodeBtn', function (){
let commonCodeList = []; const codeList = [];
$(".valueCheckBox:checked").each(function (idx, el){ $(".valueCheckBox:checked").each(function (idx, el){
commonCodeList.push({codeSq: el.value, isDeleted:'Y'}); codeList.push({});
codeList[idx].codeSq = Number(el.value);
codeList[idx].isDeleted = 'Y';
}) })
$.ajaxSettings.traditional = true;
$.ajax({ $.ajax({
url : "/admin/updateCommonCode", type : 'POST',
type : 'PUT', url : "/admin/deleteCode",
data : commonCodeList, data : JSON.stringify(codeList),
dataType: 'json', contentType: 'application/json',
beforeSend: function (xhr){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(data) { success : function(data) {
debugger debugger
}, },

View File

@ -9,6 +9,8 @@
</th:block> </th:block>
<div layout:fragment="content"> <div layout:fragment="content">
<main> <main>
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<h4>코드 관리</h4> <h4>코드 관리</h4>
<div class="row mx-0"> <div class="row mx-0">
<div class="col-6 card text-center"> <div class="col-6 card text-center">

View File

@ -13,7 +13,11 @@
<tbody> <tbody>
<tr class="valueTr" th:each="commonCode:${valueList}"> <tr class="valueTr" th:each="commonCode:${valueList}">
<td> <td>
<input type="checkbox" class="valueCheckBox" th:value="${commonCode.codeSq}"> <input type="checkbox" class="valueCheckBox"
th:data-codeSq="${commonCode.codeSq}"
th:data-category="${commonCode.category}"
th:data-value="${commonCode.value}"
th:data-description="${commonCode.description}">
</td> </td>
<td th:text="${commonCode.value}"></td> <td th:text="${commonCode.value}"></td>
<td th:text="${commonCode.description}"></td> <td th:text="${commonCode.description}"></td>

View File

@ -9,6 +9,7 @@
<!-- Security config의 loginPage("url")와 action url과 동일하게 작성--> <!-- Security config의 loginPage("url")와 action url과 동일하게 작성-->
<form action="/user/login" method="post"> <form action="/user/login" method="post">
<!-- Spring Security가 적용되면 POST 방식으로 보내는 모든 데이터는 csrf 토큰 값이 필요 --> <!-- Spring Security가 적용되면 POST 방식으로 보내는 모든 데이터는 csrf 토큰 값이 필요 -->
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/> <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<p th:if="${loginError}" class="error">Wrong user or password</p> <p th:if="${loginError}" class="error">Wrong user or password</p>
<!-- 로그인 시 아이디의 name 애트리뷰트 값은 username --> <!-- 로그인 시 아이디의 name 애트리뷰트 값은 username -->