IT'S DO
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값 보내기

profile

IT'S DO

@멋진놈

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!