ν°μ€ν 리 λ·°
π‘ PathVariable μ 무μμΈκ°?
- κ²½λ‘ λ³μ νμλ₯Ό μν΄ λ©μλ λ§€κ°λ³μμ μ¬μ©λ¨
- κ²½λ‘ λ³μ : μ€κ΄νΈλ‘ λλ¬μΈμΈ κ° → {id}
- url κ²½λ‘μμ λ³μ κ° μΆμΆ ν λ§€κ°λ³μμ ν λΉ
- κ²½λ‘ λ³μλ λ°λμ κ°μ κ°μ ΈμΌ νλ©°, κ°μ΄ μλ€λ©΄ 404 μ€λ₯ λ°μ
- μμΈ μ‘°ν, μμ , μμ μ κ°μ μμ μμ 리μμ€ μλ³μλ‘ μ¬μ©
π μ¬μ©λ²
// import μλ΅
@RestController
@RequestMapping("/product")
public class ProductController {
@Autowired
ProductService productService;
@GetMapping("/{id}")
public @ResponseBody ApiResponse<ProductSelectResponseDto> selectProduct(@PathVariable Long id) throws Exception{
return ApiResponse.OK(productService.selectProduct(id));
}
// μΆμΆν λ³μ κ°μ΄ 2κ°μ§ μ΄μμΈ κ²½μ°
@GetMapping("/{id}/{name}")
public String user(@PathVariable Long id, @PathVariable String name) {
System.out.println("μ ν λ²νΈλ " + id);
System.out.println("μ΄λ¦μ " + name);
return "index";
}
}
μλ₯Ό λ€μ΄, μλμ κ°μ URLμμ μμΉ ν λΆλΆμ @PathVariableλ‘ μ²λ¦¬ν μ μλ€.
β blog.naver.com/1234
β‘ seewol.tistory.com/5/μμ μΈνΈ
'π' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
μν μ‘°ν λ‘μ§ κ΅¬ννκΈ° (0) | 2024.08.03 |
---|---|
μν λ±λ‘ λ‘μ§ κ΅¬ννκΈ° (0) | 2024.06.16 |
[JPA] @CreatedDateμ @EntityListeners(AuditingEntityListener.class) (0) | 2024.04.17 |
[JPA] DB μ€μ (0) | 2024.02.16 |
[SQLD] λ°μ΄ν° λͺ¨λΈκ³Ό μ±λ₯ (0) | 2024.02.15 |
λκΈ