axios post

oyt4ldly  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(354)

我有一个项目,规格如下:
数据库:

Table: User
Columns: user_id, username, password
Table: Ticket
Columns: ticket_id, ticketname, ... , user_id

所以表ticket中的用户id是一个外键。
现在,我正试图做一个axios职位这样;

insert(ticket) {
            return axios
                .post(API_URL + 'insertTicket', {
                        subject: ticket.subject,
                        issue: ticket.issue,
                        company: ticket.company,
                        date: datetime,
                        user: JSON.parse(localStorage.getItem('user'))["user"],
                }
                ,{headers: authHeader() })
            .then(response => {
                return response.data;
            });
        }

这是我的机票实体:

@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "tickets")
public class Ticket {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "tickets_id")
    private int id;

    @Column(name = "tickets_status")                        // 0 = geschlossen, 1 = offen, 2 = in Bearbeitung, 3 = geloescht
    private int status;

    @Column(name = "tickets_subject")
    private String subject;

    @Column(name = "tickets_issue")
    private String issue;

    @Column(name = "tickets_adddescription")
    private String adddescription;

    @Column(name = "tickets_steps")
    private String steps;

    @Column(name = "tickets_date")
    private String date;

    @Column(name = "tickets_company")
    private String company;

    @ManyToOne
    private User users;

    public Ticket(int status, String subject, String issue, String adddescription, String steps, String date, String company, User users) {
        this.status = status;
        this.subject = subject;
        this.issue = issue;
        this.adddescription = adddescription;
        this.steps = steps;
        this.date = date;
        this.company = company;
        this.users = users;
    }
}

出现了这样一个问题:在数据库中,用户id是int,但在java代码中,它是entity:user的类型。我怎样才能在post中获得从json到表票证的用户id?

niknxzdl

niknxzdl1#

axios负载的主体:

{
                        subject: ticket.subject,
                        issue: ticket.issue,
                        company: ticket.company,
                        date: datetime,
                        user: JSON.parse(localStorage.getItem('user'))["user"],
                }

有道具的名字吗 subject, issue, company, date, user 例如,这些属性与您在票证实体中拥有的道具名称不直接匹配 (name = "tickets_id") 我建议在用vuejs编写axios文章之前,使用postman测试它。在将文章放入vuejs和axios之前,运行tickets api并获取正确的道具名称和标题。

相关问题