Home > AI > Backend > SpringBoot >

@ResponseBody

The REST API reponse is JSON format.

Example:

ExamplePostController.java

@Controller
@RequestMapping("/post")
public class ExamplePostController {
    @PostMapping("/response")
    @ResponseBody
    public ResponseTransfer postResponseController(
            @RequestBody LoginForm loginForm) {
        return new ResponseTransfer("Thanks For Posting!!!");
    }
}

LoginForm.java

public class LoginForm {
    public String name;
    public String title;
}

ResponseTransfer.java

@Data
@AllArgsConstructor
public class ResponseTransfer {
    private String text;
}

Leave a Reply