중간저장.
parent
0a10167487
commit
3bf841d809
|
|
@ -27,8 +27,6 @@ dependencies {
|
|||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
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.thymeleaf.extras:thymeleaf-extras-springsecurity5'
|
||||
|
|
|
|||
|
|
@ -4,27 +4,32 @@ import com.dbnt.kcgfilemanager.model.UserInfo;
|
|||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
public class BaseController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String loginCheck(Principal principal) {
|
||||
public ModelAndView loginCheck(Principal principal) {
|
||||
ModelAndView mav = null;
|
||||
if(principal == null){
|
||||
return "redirect:/user/login";
|
||||
mav = new ModelAndView("redirect:/user/login");
|
||||
}else{
|
||||
if(((UserInfo)((UsernamePasswordAuthenticationToken) principal).getPrincipal()).getUserRole().indexOf("ADMIN")>0){
|
||||
return "redirect:/admin/main";
|
||||
mav = new ModelAndView("redirect:/admin/main");
|
||||
}else{
|
||||
return "redirect:/user/main";
|
||||
mav = new ModelAndView("redirect:/user/main");
|
||||
}
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
|
||||
@GetMapping("/user/main")
|
||||
public String main() {
|
||||
return "main";
|
||||
public ModelAndView main() {
|
||||
ModelAndView mav = new ModelAndView("main");
|
||||
return mav;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import org.springframework.stereotype.Controller;
|
|||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class UserInfoController {
|
||||
|
||||
|
|
@ -16,34 +18,39 @@ public class UserInfoController {
|
|||
|
||||
/** * 로그인 페이지 이동 * @return */
|
||||
@GetMapping("/user/login")
|
||||
public String goLogin() {
|
||||
return "login";
|
||||
public ModelAndView goLogin() {
|
||||
ModelAndView mav = new ModelAndView("login");
|
||||
return mav;
|
||||
}
|
||||
|
||||
/** * 로그인 에러 * @param model * @return */
|
||||
@GetMapping("/login-error")
|
||||
public String loginError(Model model) {
|
||||
model.addAttribute("loginError", true);
|
||||
return "/login";
|
||||
public ModelAndView loginError() {
|
||||
ModelAndView mav = new ModelAndView("/login");
|
||||
mav.addObject("loginError", true);
|
||||
return mav;
|
||||
}
|
||||
|
||||
/** * 회원가입 처리 * @param memberDto * @return */
|
||||
@PostMapping("/signup")
|
||||
public String signup(UserInfo userInfo) {
|
||||
public ModelAndView signup(UserInfo userInfo) {
|
||||
ModelAndView mav = new ModelAndView("redirect:/user/login");
|
||||
userInfoService.signup(userInfo);
|
||||
return "redirect:/user/login";
|
||||
return mav;
|
||||
}
|
||||
|
||||
/** * 접근 거부 페이지 이동 * @return */
|
||||
@GetMapping("/denied")
|
||||
public String doDenied() {
|
||||
return "login/denied";
|
||||
public ModelAndView doDenied() {
|
||||
ModelAndView mav = new ModelAndView("login/denied");
|
||||
return mav;
|
||||
}
|
||||
|
||||
/** * 내 정보 페이지 이동 * @return */
|
||||
@GetMapping("/info")
|
||||
public String goMyInfo() {
|
||||
return "login/myinfo";
|
||||
public ModelAndView goMyInfo() {
|
||||
ModelAndView mav = new ModelAndView("login/myinfo");
|
||||
return mav;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,44 +3,40 @@ 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.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
@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";
|
||||
public ModelAndView goAdmin() {
|
||||
ModelAndView mav = new ModelAndView("admin/main");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@GetMapping("/userMgt")
|
||||
public String userMgt() {
|
||||
return "admin/userMgt";
|
||||
public ModelAndView userMgt() {
|
||||
ModelAndView mav = new ModelAndView("admin/userMgt");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@GetMapping("/modifyRequest")
|
||||
public String modifyRequest() {
|
||||
return "admin/modifyRequest";
|
||||
public ModelAndView modifyRequest() {
|
||||
ModelAndView mav = new ModelAndView("admin/modifyRequest");
|
||||
return mav;
|
||||
}
|
||||
|
||||
@GetMapping("/codeMgt")
|
||||
|
|
@ -57,36 +53,23 @@ public class adminController {
|
|||
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();
|
||||
@PutMapping("/insertCode")
|
||||
public CommonCode insertCommonCode(CommonCode commonCode){
|
||||
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();
|
||||
return commonCode;
|
||||
}
|
||||
writerJson.print(jsonObject);
|
||||
}
|
||||
@PutMapping("/updateCommonCode")
|
||||
public void updateCommonCode(HttpServletResponse res, List<CommonCode> 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);
|
||||
|
||||
@PostMapping(value = "/deleteCode")
|
||||
@ResponseBody
|
||||
public int deleteCommonCode(
|
||||
// @RequestBody HashMap<String, Object> map
|
||||
// @RequestBody CommonCode code
|
||||
@RequestBody List<CommonCode> codeList
|
||||
) {
|
||||
// return map.size();
|
||||
// return code.getCodeSq();
|
||||
commonCodeService.updateCommonCode(codeList);
|
||||
return codeList.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.dbnt.kcgfilemanager.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
|
|
@ -10,19 +8,19 @@ import javax.persistence.*;
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Entity
|
||||
@Table(name = "COMMON_CODE")
|
||||
public class CommonCode {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "CODE_SQ")
|
||||
private Integer codeSq;
|
||||
@Column(name = "CATEGORY")
|
||||
@Column(name = "CATEGORY", nullable = false)
|
||||
private String category;
|
||||
@Column(name = "VALUE")
|
||||
@Column(name = "VALUE", nullable = false)
|
||||
private String value;
|
||||
@Column(name = "DESCRIPTION")
|
||||
private String description;
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ import java.util.Set;
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Entity
|
||||
@Table(name = "USER_INFO")
|
||||
public class UserInfo implements UserDetails{
|
||||
@Id
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ package com.dbnt.kcgfilemanager.repository;
|
|||
import com.dbnt.kcgfilemanager.model.CommonCode;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface CommonCodeRepository extends JpaRepository<CommonCode, Integer> {
|
||||
|
||||
List<CommonCode> findByCategory(String category);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,13 @@ public class CommonCodeService {
|
|||
return commonCodeMapper.selectCommonCodeCategory(commonCode);
|
||||
}
|
||||
public List<CommonCode> selectCommonCodeValue(CommonCode commonCode) {
|
||||
return commonCodeMapper.selectCommonCodeValue(commonCode);
|
||||
return commonCodeRepository.findByCategory(commonCode.getCategory());
|
||||
}
|
||||
public void insertCommonCode(CommonCode commonCode) {
|
||||
commonCodeRepository.save(commonCode);
|
||||
}
|
||||
|
||||
public void updateCommonCode(List<CommonCode> codeList) {
|
||||
commonCodeRepository.saveAll(codeList);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,11 @@ $(document).on('click', '#saveBtn', function (){
|
|||
if(confirm("저장하시겠습니까?")){
|
||||
const formData = new FormData($("#commonCodeForm")[0]);
|
||||
$.ajax({
|
||||
processData: false,
|
||||
contentType: false,
|
||||
url : "/admin/insertCommonCode",
|
||||
type : 'PUT',
|
||||
data : formData,
|
||||
dataType: 'json',
|
||||
url : "/admin/insertCode",
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success : function(data) {
|
||||
alert("저장되었습니다.")
|
||||
$("#closeModalBtn").click();
|
||||
|
|
@ -65,15 +64,21 @@ $(document).on('click', '#saveBtn', function (){
|
|||
}
|
||||
})
|
||||
$(document).on('click', '#deleteCommonCodeBtn', function (){
|
||||
let commonCodeList = [];
|
||||
const codeList = [];
|
||||
$(".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({
|
||||
url : "/admin/updateCommonCode",
|
||||
type : 'PUT',
|
||||
data : commonCodeList,
|
||||
dataType: 'json',
|
||||
type : 'POST',
|
||||
url : "/admin/deleteCode",
|
||||
data : JSON.stringify(codeList),
|
||||
contentType: 'application/json',
|
||||
beforeSend: function (xhr){
|
||||
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
|
||||
},
|
||||
success : function(data) {
|
||||
debugger
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
</th:block>
|
||||
<div layout:fragment="content">
|
||||
<main>
|
||||
<input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
|
||||
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
|
||||
<h4>코드 관리</h4>
|
||||
<div class="row mx-0">
|
||||
<div class="col-6 card text-center">
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@
|
|||
<tbody>
|
||||
<tr class="valueTr" th:each="commonCode:${valueList}">
|
||||
<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 th:text="${commonCode.value}"></td>
|
||||
<td th:text="${commonCode.description}"></td>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
<!-- Security config의 loginPage("url")와 action url과 동일하게 작성-->
|
||||
<form action="/user/login" method="post">
|
||||
<!-- 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}"/>
|
||||
<p th:if="${loginError}" class="error">Wrong user or password</p>
|
||||
<!-- 로그인 시 아이디의 name 애트리뷰트 값은 username -->
|
||||
|
|
|
|||
Loading…
Reference in New Issue