단어사전 ver1 완료
This commit is contained in:
parent
bab61328a7
commit
7fb0d34419
@ -11,4 +11,8 @@ public interface DictionaryMapper {
|
||||
List<DictionaryVO> findAll();
|
||||
|
||||
void save(DictionaryVO dictionaryVO);
|
||||
|
||||
void delete(DictionaryVO dictionaryVO);
|
||||
|
||||
void insert(DictionaryVO dictionaryVO);
|
||||
}
|
||||
|
||||
@ -33,15 +33,17 @@ public class DictionaryServiceImpl implements DictionaryService {
|
||||
Map<String, Object> data = (Map<String, Object>) dictionaryMap.get("data");
|
||||
String action = (String) dictionaryMap.get("action");
|
||||
|
||||
DictionaryVO dictionaryVO = getSingleDate(dictionaryMap);
|
||||
if("edit".equals(action)) {
|
||||
DictionaryVO dictionaryVO = getSingleDate(dictionaryMap);
|
||||
System.out.println(dictionaryVO);
|
||||
dictionaryMapper.save(dictionaryVO);
|
||||
|
||||
}else if("remove".equals(action)) {
|
||||
List<DictionaryVO> getMultiDate = getMultiDate(dictionaryMap);
|
||||
System.out.println(dictionaryVO);
|
||||
dictionaryMapper.delete(dictionaryVO);
|
||||
}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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -46,4 +46,29 @@
|
||||
</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>
|
||||
@ -20,6 +20,9 @@
|
||||
border: none;
|
||||
color: inherit;
|
||||
}
|
||||
.dtcenter {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@ -61,7 +64,7 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title">목록</h3>
|
||||
<h3 class="card-title">목록 - 클릭하면 수정 가능합니다.</h3>
|
||||
</div>
|
||||
<!-- /.card-header -->
|
||||
<div class="card-body">
|
||||
@ -137,39 +140,30 @@
|
||||
},
|
||||
idSrc: 'id', // 이렇게 `idSrc` 속성을 사용하여 식별자를 지정합니다.
|
||||
table: '#dicTb',
|
||||
i18n: {
|
||||
remove: {
|
||||
title: '행 삭제 확인',
|
||||
confirm: {
|
||||
_: '선택하신 %d개의 행을 삭제하시겠습니까?', // 복수 행 삭제 시 메시지
|
||||
1: '이 행을 삭제하시겠습니까?' // 단일 행 삭제 시 메시지
|
||||
}
|
||||
}
|
||||
},
|
||||
formOptions: {
|
||||
inline: {
|
||||
onBlur: 'submit'
|
||||
}
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경
|
||||
name: 'id'
|
||||
},
|
||||
// {
|
||||
// label: 'ID:', // "ID" 대신 다른 레이블을 사용하고 싶다면 여기를 변경
|
||||
// name: 'id'
|
||||
// },
|
||||
{
|
||||
label: '한국어 단어:', // "koreanWord"의 레이블을 "한국어 단어"로 변경
|
||||
name: 'koreanWord'
|
||||
name: 'koreanWord', attr: { required: 'required' }
|
||||
},
|
||||
{
|
||||
label: '영어 단어:', // "englishWord"의 레이블을 "영어 단어"로 변경
|
||||
name: 'englishWord'
|
||||
name: 'englishWord', attr: { required: 'required' }
|
||||
},
|
||||
{
|
||||
label: '약어:', // "abbreviation"의 레이블을 "약어"로 변경
|
||||
name: 'abbreviation'
|
||||
name: 'abbreviation', attr: { required: 'required' }
|
||||
},
|
||||
{
|
||||
label: '확인 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경
|
||||
label: '확정 여부:', // "Is Confirmed"의 레이블을 "확인 여부"로 변경
|
||||
name: 'isConfirmed',
|
||||
type: 'select',
|
||||
options: [
|
||||
@ -192,12 +186,7 @@
|
||||
dataSrc: ''
|
||||
},
|
||||
columns: [
|
||||
// {
|
||||
// data: 'id',
|
||||
// orderable: false,
|
||||
// render: DataTable.render.select()
|
||||
// },,
|
||||
{ data: 'id' }, // ID 컬럼을 추가하고 숨깁니다.
|
||||
{ data: 'id' },
|
||||
{
|
||||
data: null,
|
||||
className: 'dt-center editor-delete',
|
||||
@ -224,29 +213,69 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
order: [1, 'asc'],
|
||||
order: [0, 'asc'],
|
||||
select: {
|
||||
style: 'os',
|
||||
selector: 'td:first-child'
|
||||
}
|
||||
});
|
||||
|
||||
$('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) {
|
||||
editor.inline(this);
|
||||
});
|
||||
editor.on('submitSuccess', function() {
|
||||
// editor.DataTable().destroy();
|
||||
table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드
|
||||
});
|
||||
|
||||
// Delete a record
|
||||
table.on('click', 'td.editor-delete button', function (e) {
|
||||
editor.remove(e.target.closest('tr'), {
|
||||
title: 'Delete record',
|
||||
message: 'Are you sure you wish to remove this record?',
|
||||
buttons: 'Delete'
|
||||
// 필드 클릭해서 수정할수 있는 옵션
|
||||
$('#dicTb').on('click', 'tbody td:not(:first-child)', function (e) {
|
||||
editor.inline(this);
|
||||
});
|
||||
editor.on('submitSuccess', function() {
|
||||
// editor.DataTable().destroy();
|
||||
table.ajax.reload(null, false); // 수정이 성공한 후 테이블 데이터 리로드
|
||||
});
|
||||
|
||||
// 삭제 버튼 클릭 이벤트
|
||||
table.on('click', 'td.editor-delete button', function (e) {
|
||||
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',
|
||||
message: message, // 직접 메시지 전달
|
||||
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>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user