Ajax로 데이터 보내기

박예림·2024년 3월 19일
0

@RequestParam Request Header에 Parameter를 넣어 전달
@RequestBody Request Body에 Data를 넣어 전달

@RequestMapping("/create")
public Map<String, Object> create(@RequestBody Map<String ,Object> data, HttpServletRequest request) throws PageException
{
createState(getLoginUserId(request),"생성");

Map<String, Object> result;

PostVo postVo = new PostVo();
postVo.setTitle(data.get("title").toString());
postVo.setContent(data.get("content").toString());
postVo.setUserId(getLoginUserId(request));
result = postService.createPost(postVo);

return result;

}

const title = $("#title").val();
const content = $("#content").val();
const data = { title: title, content: content };


fetch("/post/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
},

body: JSON.stringify(data),

})
profile
응애 나 아기개발자

0개의 댓글