단어사전 ver1 완료

This commit is contained in:
hylee 2024-05-09 12:35:19 +09:00
parent bab61328a7
commit 7fb0d34419
4 changed files with 103 additions and 63 deletions

View File

@ -11,4 +11,8 @@ public interface DictionaryMapper {
List<DictionaryVO> findAll(); List<DictionaryVO> findAll();
void save(DictionaryVO dictionaryVO); void save(DictionaryVO dictionaryVO);
void delete(DictionaryVO dictionaryVO);
void insert(DictionaryVO dictionaryVO);
} }

View File

@ -33,15 +33,17 @@ public class DictionaryServiceImpl implements DictionaryService {
Map<String, Object> data = (Map<String, Object>) dictionaryMap.get("data"); Map<String, Object> data = (Map<String, Object>) dictionaryMap.get("data");
String action = (String) dictionaryMap.get("action"); String action = (String) dictionaryMap.get("action");
if("edit".equals(action)) {
DictionaryVO dictionaryVO = getSingleDate(dictionaryMap); DictionaryVO dictionaryVO = getSingleDate(dictionaryMap);
if("edit".equals(action)) {
System.out.println(dictionaryVO); System.out.println(dictionaryVO);
dictionaryMapper.save(dictionaryVO); dictionaryMapper.save(dictionaryVO);
}else if("remove".equals(action)) { }else if("remove".equals(action)) {
List<DictionaryVO> getMultiDate = getMultiDate(dictionaryMap); System.out.println(dictionaryVO);
dictionaryMapper.delete(dictionaryVO);
}else if("create".equals(action)) { }else if("create".equals(action)) {
DictionaryVO dictionaryVO = getSingleDate(dictionaryMap); System.out.println(dictionaryVO);
dictionaryMapper.insert(dictionaryVO);
} }
} }
@ -69,25 +71,5 @@ public class DictionaryServiceImpl implements DictionaryService {
} }
private static List<DictionaryVO> getMultiDate(Map<String, Object> dictionaryMap) {
Map<String, Object> data = (Map<String, Object>) dictionaryMap.get("data");
List<DictionaryVO> dictionaries = new ArrayList<>();
for (Map.Entry<String, Object> entry : data.entrySet()) {
Map<String, Object> dictionaryData = (Map<String, Object>) entry.getValue();
DictionaryVO dictionary = new DictionaryVO();
dictionary.setId(Long.parseLong(entry.getKey()));
dictionary.setEnglishWord((String) dictionaryData.get("englishWord"));
dictionary.setKoreanWord((String) dictionaryData.get("koreanWord"));
dictionary.setAbbreviation((String) dictionaryData.get("abbreviation"));
dictionary.setIsConfirmed((String) dictionaryData.get("isConfirmed"));
dictionary.setIsActive((String) dictionaryData.get("isActive"));
dictionaries.add(dictionary);
}
return dictionaries;
}
} }

View File

@ -46,4 +46,29 @@
</update> </update>
<delete id="delete" parameterType="dictionaryVO">
DELETE FROM dictionary
WHERE id = #{id}
</delete>
<insert id="insert" parameterType="dictionaryVO">
insert into dictionary
(
KOREAN_WORD
, ENGLISH_WORD
, ABBREVIATION
, IS_CONFIRMED
, FRST_REGIST_PNTTM
)
values
(
#{koreanWord}
, #{englishWord}
, #{abbreviation}
, #{isConfirmed}
, NOW()
);
</insert>
</mapper> </mapper>

View File

@ -20,6 +20,9 @@
border: none; border: none;
color: inherit; color: inherit;
} }
.dtcenter {
text-align: center;
}
</style> </style>
</head> </head>
@ -61,7 +64,7 @@
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">
<h3 class="card-title">목록</h3> <h3 class="card-title">목록 - 클릭하면 수정 가능합니다.</h3>
</div> </div>
<!-- /.card-header --> <!-- /.card-header -->
<div class="card-body"> <div class="card-body">
@ -137,39 +140,30 @@
}, },
idSrc: 'id', // 이렇게 `idSrc` 속성을 사용하여 식별자를 지정합니다. idSrc: 'id', // 이렇게 `idSrc` 속성을 사용하여 식별자를 지정합니다.
table: '#dicTb', table: '#dicTb',
i18n: {
remove: {
title: '행 삭제 확인',
confirm: {
_: '선택하신 %d개의 행을 삭제하시겠습니까?', // 복수 행 삭제 시 메시지
1: '이 행을 삭제하시겠습니까?' // 단일 행 삭제 시 메시지
}
}
},
formOptions: { formOptions: {
inline: { inline: {
onBlur: 'submit' onBlur: 'submit'
} }
}, },
fields: [ fields: [
{ // {
label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경 // label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경
name: 'id' // name: 'id'
}, // },
{ {
label: '한국어 단어:', // "koreanWord"의 레이블을 "한국어 단어"로 변경 label: '한국어 단어:', // "koreanWord"의 레이블을 "한국어 단어"로 변경
name: 'koreanWord' name: 'koreanWord', attr: { required: 'required' }
}, },
{ {
label: '영어 단어:', // "englishWord"의 레이블을 "영어 단어"로 변경 label: '영어 단어:', // "englishWord"의 레이블을 "영어 단어"로 변경
name: 'englishWord' name: 'englishWord', attr: { required: 'required' }
}, },
{ {
label: '약어:', // "abbreviation"의 레이블을 "약어"로 변경 label: '약어:', // "abbreviation"의 레이블을 "약어"로 변경
name: 'abbreviation' name: 'abbreviation', attr: { required: 'required' }
}, },
{ {
label: '확 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경 label: '확 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경
name: 'isConfirmed', name: 'isConfirmed',
type: 'select', type: 'select',
options: [ options: [
@ -192,12 +186,7 @@
dataSrc: '' dataSrc: ''
}, },
columns: [ columns: [
// { { data: 'id' },
// data: 'id',
// orderable: false,
// render: DataTable.render.select()
// },,
{ data: 'id' }, // ID 컬럼을 추가하고 숨깁니다.
{ {
data: null, data: null,
className: 'dt-center editor-delete', className: 'dt-center editor-delete',
@ -224,13 +213,14 @@
] ]
} }
}, },
order: [1, 'asc'], order: [0, 'asc'],
select: { select: {
style: 'os', style: 'os',
selector: 'td:first-child' selector: 'td:first-child'
} }
}); });
// 필드 클릭해서 수정할수 있는 옵션
$('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) { $('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) {
editor.inline(this); editor.inline(this);
}); });
@ -239,15 +229,54 @@
table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드 table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드
}); });
// Delete a record // 삭제 버튼 클릭 이벤트
table.on('click', 'td.editor-delete button', function (e) { table.on('click', 'td.editor-delete button', function (e) {
editor.remove(e.target.closest('tr'), { var tr = $(this).closest('tr');
var row = table.row(tr).data();
var message = '"' + row.koreanWord + '" (' + row.englishWord + ') 삭제 하시겠습니까?';
editor.message(message);
editor.remove(tr, {
title: 'Delete record', title: 'Delete record',
message: 'Are you sure you wish to remove this record?', message: message, // 직접 메시지 전달
buttons: 'Delete' buttons: 'Delete'
}); });
}); });
// 데이터 제출 전에 유효성 검사 수행
editor.on('preSubmit', function (e, data, action) {
if(action == 'create'){
var error = false;
var errorMsg = '';
// Loop through all the data items
for (var key in data.data) {
var entry = data.data[key];
// Validate Korean Word
if (!entry.koreanWord || entry.koreanWord.trim() === '') {
error = true;
errorMsg += '한국어 단어를 입력해주세요.\n';
}else if (!entry.englishWord || entry.englishWord.trim() === '') {
error = true;
errorMsg += '영어 단어를 입력해주세요.\n';
}else if (!entry.abbreviation || entry.abbreviation.trim() === '') {
error = true;
errorMsg += '약어를 입력해주세요.\n';
}
}
// If any error was detected, prevent submission and display the error message
if (error) {
this.error(errorMsg);
return false; // prevent submission
}
}
});
</script> </script>
</body> </body>