728x90
/**
* 게시글 조회
*/
function findBoard() {
const id = /*[[ ${id} ]]*/;
fetch(`/api/events/${id}`).then(response => {
if (!response.ok) {
throw new Error('Request failed...');
}
return response.json();
}).then(json => {
console.table(json);
json.createdDate = moment(json.createdDate).format('YYYY-MM-DD HH:mm:ss');
Object.keys(json).forEach(key => {
const elem = document.getElementById(key);
if (elem) {
elem.innerText = json[key];
}
});
}).catch(error => {
alert('게시글 정보를 찾을 수 없습니다.');
goList();
});
}
먼저 json 데이터를 파싱하기
window.onload = () => {
findBoard();
}
데이터를 온로드 해주고
<a href="javascript: void(0);" onclick="goWrite();" class="btn btn-primary waves-effect waves-light">수정하기</a>
버튼으로
id값 보내기
function goWrite() {
location.href = `/event/write?id=[[ ${id} ]]`;
}
@GetMapping("/write")
public String openBoardWrite(@RequestParam(required = false) final Long id, Model model) {
model.addAttribute("id", id);
return "thymeleaf/event/write";
}
그리고 model에 담아서 아이디 값을 담고 나서, controller로 id값 보내기
'개발 > Spring Boot' 카테고리의 다른 글
springBoot 파일 용량 늘리기 (0) | 2022.09.21 |
---|---|
프로젝트 이름 변경하니 발생한 에러 및 변경 방법. (0) | 2022.08.29 |
springboot 튜닝 application.yml hikari (0) | 2022.07.29 |
Thymeleaf 비교 연산, 리터럴 정보 좋은 사이트 (0) | 2022.07.28 |
Thymeleaf controller에서 값 받아오기 및 th:each 등 사용법 값 받기 값 담아오기 (0) | 2022.07.28 |