[spring] URL로 파라미터를 전달하는 방법(@RequestParam, @PathVariable)

Chaewon Yoon (Jamie)·2023년 2월 17일
0

[Today I learned]

목록 보기
27/32

(FrontController.java)

Query String (@RequestParam) "?"

url: http://localhost:8080/view/service/setting?serviceId=3

@GetMapping("/view/service/setting")
    public String viewService2(@RequestParam("serviceId") Long serviceId) {
        return "view/service-setting";
    }
$('#service-table tbody').on('click', '.replace ', function () {
    var data = $('#service-table').DataTable().row($(this).parents('tr')).data();
    const serviceId = data.serviceId;
    console.log(serviceId);
    location.href=`/view/service/setting?serviceId=${serviceId}`;
});

URL 변수 (@PathVariable)

url: http://localhost:8080/view/service/setting/3

@GetMapping("/view/service/setting")
    public String viewService2(@RequestParam("serviceId") Long serviceId) {
        return "view/service-setting";
    }
$('#service-table tbody').on('click', '.replace ', function () {
    var data = $('#service-table').DataTable().row($(this).parents('tr')).data();
    const serviceId = data.serviceId;
    console.log(serviceId);
    location.href=`/view/service/setting/${serviceId}`;
});
profile
keep growing as a web developer!🧃

0개의 댓글