【问题标题】:Spring boot controller [closed]春季启动控制器[关闭]
【发布时间】:2023-03-25 17:46:01
【问题描述】:

我最近开始学习 Spring-Boot,但我陷入了困境。 完整项目的 GitHub 链接就在这里https://github.com/Timmy1505/springbooy-app.git 我有一个休息控制器,我想将其更改为控制器并呈现 thymeleaf 模板(registration_form)并发布请求

代码:

@RestController
@RequestMapping(path = "api/v1/registration")
@AllArgsConstructor
public class RegistrationController {

    private final RegistrationService registrationService;

    @PostMapping
    public String register(@RequestBody RegistrationRequest request) {
        return registrationService.register(request);
    }

    @GetMapping(path = "confirm")
    public String confirm(@RequestParam("token") String token) {
        return registrationService.confirmToken(token);
    }
}

【问题讨论】:

  • 你这样做有什么问题?
  • 我想渲染 HTML 页面以进行注册并执行请求

标签: java spring-boot http-post get-request


【解决方案1】:

@RestController 更改为@Controller 以支持视图渲染。

【讨论】:

  • 好的,谢谢。但我希望我的模板包中的registration_form.htm 被渲染并执行操作。我已经使用邮递员对其进行了测试以发布请求,并且它工作得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-11
  • 2015-04-18
  • 2017-06-24
  • 2015-08-22
  • 2015-09-18
  • 2015-03-20
  • 2018-01-24
相关资源
最近更新 更多