반응형
//restapi 처리하는 controller
@RestController
@RequestMapping("/api")
public class ApiController {
@GetMapping("/hello")
public String hello(){
return "hello";
}
@GetMapping("/path-variable/{name}")
public String pathVariable(@PathVariable(name = "name")String pathName){
return pathName;
@GetMapping("/path-variable/{name}")
public String pathVariable(@PathVariable String name){
return name;
}
@GetMapping("path")
public String path(@RequestParam String name2
)
{
return name2;
}
@GetMapping("path2")
public String path(UserRequest userRequest
)
{
return userRequest.getName();
}
+dto
package com.example.demo.dto;
public class UserRequest {
private String name;
private String email;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}
반응형