ex) http://localhost:8080/tutor?name=wonuk&age=100
POST /form-data
content-type: application/x-www-form-urlencoded
**key1=value1&key2=value2**
@ResponseBody
@GetMapping("/v4/request-param")
public String requestParam (
@RequestParam(required = true) String name, // 필수
@RequestParam(required = false) Integer age
) {
// logic
log.info("name={}", name);
log.info("age={}", age);
return "success";
}@ResponseBody
@PostMapping("/v2/tutor")
public String modelAttributeV2(
@ModelAttribute Tutor tutor
) {
String name = tutor.getName();
int age = tutor.getAge();
return "tutor name = " + name + " age = " + age;
}
데이터(JSON, TEXT, XML 등)를 직접 HTTP Message Body에 담아서 사용
사용하는 어노테이션
src/main/resources/static/hello/world.html 디렉토리 구조라면http://localhost:8080/hello/world.html URL로 리소스에 접근@Controller
public class ViewTemplateController {
@RequestMapping("/response-view")
public String responseView(Model model) {
// key, value
model.addAttribute("data", "sparta");
return "thymeleaf-view";
}
}