简体   繁体   English

无法从请求正文中读取

[英]Unable to read from request body

I'm trying to send an email where the values are dependent on the values from the form in the Frontend, but they are always null.我正在尝试发送一个 email,其中的值取决于前端表单中的值,但它们始终是 null。

Controller Controller

    @PostMapping("/send")
    public void sendEmail(Contact contact) throws MessagingException {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setTo("test@gmail.com");
        mailMessage.setSubject(contact.getSubject()); //This is always null
        mailMessage.setFrom("arasto.developer@gmail.com");
        mailMessage.setText("To confirm ationToken()););");
        emailSenderService.sendEmail(mailMessage);
    }

Entity实体

public class Contact {

    private String email;
    private String address;
    private String subject;
    private String content;

    public Contact() { }

    //...getters & setters


My Post , This gives me 200 OK我的帖子,这给了我200 OK 在此处输入图像描述


Result Subject not being displayed.结果未显示主题。 在此处输入图像描述

Any suggestions of where i've gone wrong and how i could correct this are much appreciated.任何关于我哪里出错以及如何纠正这个问题的建议都非常感谢。

Prepend method parameter with @RequestBody annotation as below:在方法参数前面加上@RequestBody注释,如下所示:

public void sendEmail(@RequestBody Contact contact) throws MessagingException { public void sendEmail(@RequestBody Contact contact) 抛出 MessagingException {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM