db에 값이 잘 저장될지 ajax콜을 날려서 확인해보자
1.js 작성
<script>
function postwrite() {
let username = $("#name").val();
let password = $("#password").val();
let title = $("#title").val();
let description = $("#description").val();
var jsonData = { // Body에 첨부할 json 데이터
"username":username,
"password":password,
"title":title,
"description":description
};
$.ajax({
type: "POST",
url: '/post/write',
contentType: "application/json",
data: JSON.stringify(jsonData),
success: function (response) {
console.log("저장 완료")
}
})
}
</script>
저장은 잘 되었는데 2가지 트러블이 있었다.
1.Controller 안에 return을 ""로 임시로 해둔 것을 깜빡하고 요청을 계속 보냈다. 요청 처리 이후에 돌아갈 길이 없으니 타임리프 에러가 났다. main으로 돌아가도록 설정해주니 에러가 해결됐다.
2.db 연결할때 url설정을 잘못했다.. 그래서 db가 intellij에서는 확인 가능한데 h2 console에서는 에러가 났다. db 설정을 처음부터 다시 해야겠다.