글 등록

boardList.vue
<button type="button" @click="$router.push('/writer')" class="btn btn-outline-primary">글작성 </button>
boardWriter.vue
<form novalidate>
<div class="panel-body">
<div class="form-group">
<label>제목</label>
<input placeholder="제목을 입력하세요" class="form-control" v-model="title" ref="title" name="title">
<div class="form-group">
<label>내용</label>
<textarea placeholder="내용을 입력하세요" rows="5" cols="50" v-model="content" name="content" ref="content" class="form-control"></textarea>
</div>
<div class="form-group">
<label>작성자</label>
<input placeholder="작성자를 입력하세요 " class="form-control" v-model="writer" name="writer" ref="writer" >
</div>
</div>
</div>
<div class="col-12">
</div>
</form>
<button type="button" class="btn btn-outline-primary" @click="insertBtn" v-else>등록</button>
<button type="button" class="btn btn-outline-success" @click="$router.push('/')">목록</button>
import axios from 'axios';
export default {
name:'BoardWriter',
data() {
return {
title : '',
content : '',
writer : '',
}
},
methods: {
insertBtn(){
if(this.title.trim()=="")
{
this.$refs.title.focus();
return;
}
if(this.content.trim()=="")
{
this.$refs.content.focus();
return;
}
if(this.writer.trim()=="")
{
this.$refs.writer.focus();
return;
}
axios.post('/api/writer',{
title:this.title,
content:this.content,
writer :this.writer,
}).then(()=>{
this.$router.push('/')
})
}
},
}
</script>
controller
@PostMapping("/writer")
public ResponseEntity<Integer> insertBoard(@RequestBody Map<String, Object> inMap){
log.debug("inMap" +inMap);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("title", inMap.get("title"));
dataMap.put("content", inMap.get("content"));
dataMap.put("writer", inMap.get("writer"));
int result = boardservice.register(dataMap);
if (result == 1 ) {
return new ResponseEntity<Integer>(result, HttpStatus.OK);
}else{
return new ResponseEntity<Integer>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
글삭제
BoardDetail.vue
<button type="button" class="btn btn-outline-secondary" @click="deleteBtn">삭제</button>
deleteBtn(){
axios.delete(`/api/delete/${this.id}`)
.then(()=>{
this.$router.push('/');
})
Controller
@DeleteMapping("/delete/{id}")
public ResponseEntity<Integer> deleteBoard(@PathVariable Long id){
log.debug("id" +id);
int result = boardservice.deleteBoard(id);
if (result == 1 ) {
return new ResponseEntity<Integer>(result, HttpStatus.OK);
}else{
return new ResponseEntity<Integer>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}