코드관리 페이지 완료

master
강석 최 2021-12-03 10:08:44 +09:00
parent 3bf841d809
commit ea1cb9335c
5 changed files with 30 additions and 28 deletions

View File

@ -53,21 +53,15 @@ public class adminController {
return mav;
}
@PutMapping("/insertCode")
@PostMapping("/insertCode")
public CommonCode insertCommonCode(CommonCode commonCode){
commonCodeService.insertCommonCode(commonCode);
return commonCode;
}
@PostMapping(value = "/deleteCode")
@PutMapping(value = "/deleteCode")
@ResponseBody
public int deleteCommonCode(
// @RequestBody HashMap<String, Object> map
// @RequestBody CommonCode code
@RequestBody List<CommonCode> codeList
) {
// return map.size();
// return code.getCodeSq();
public int deleteCommonCode(@RequestBody List<CommonCode> codeList) {
commonCodeService.updateCommonCode(codeList);
return codeList.size();
}

View File

@ -8,5 +8,5 @@ import java.util.List;
public interface CommonCodeRepository extends JpaRepository<CommonCode, Integer> {
List<CommonCode> findByCategory(String category);
List<CommonCode> findByCategoryAndIsDeleted(String category, String isDeleted);
}

View File

@ -26,7 +26,7 @@ public class CommonCodeService {
return commonCodeMapper.selectCommonCodeCategory(commonCode);
}
public List<CommonCode> selectCommonCodeValue(CommonCode commonCode) {
return commonCodeRepository.findByCategory(commonCode.getCategory());
return commonCodeRepository.findByCategoryAndIsDeleted(commonCode.getCategory(), "N");
}
public void insertCommonCode(CommonCode commonCode) {
commonCodeRepository.save(commonCode);

View File

@ -46,7 +46,7 @@ $(document).on('click', '#saveBtn', function (){
if(confirm("저장하시겠습니까?")){
const formData = new FormData($("#commonCodeForm")[0]);
$.ajax({
type : 'PUT',
type : 'POST',
data : formData,
url : "/admin/insertCode",
processData: false,
@ -67,12 +67,17 @@ $(document).on('click', '#deleteCommonCodeBtn', function (){
const codeList = [];
$(".valueCheckBox:checked").each(function (idx, el){
codeList.push({});
codeList[idx].codeSq = Number(el.value);
const target = $(el);
codeList[idx].codeSq = Number(target.attr("data-codesq"));
codeList[idx].category = target.attr("data-category");
codeList[idx].value = target.attr("data-value");
codeList[idx].description = target.attr("data-description");
codeList[idx].isDeleted = 'Y';
})
$.ajaxSettings.traditional = true;
if(codeList.length !== 0){
if(confirm(codeList.length+"건을 삭제하시겠습니까?")){
$.ajax({
type : 'POST',
type : 'PUT',
url : "/admin/deleteCode",
data : JSON.stringify(codeList),
contentType: 'application/json',
@ -80,12 +85,15 @@ $(document).on('click', '#deleteCommonCodeBtn', function (){
xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val());
},
success : function(data) {
debugger
alert("삭제되었습니다.");
getValues($(".categoryCheckBox:checked").val());
},
error : function(xhr, status) {
}
})
}
}
})
function getValues(category){

View File

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