gpt4 book ai didi

java - Rest Get 方法返回不正确的元素名称

转载 作者:行者123 更新时间:2023-11-30 05:45:43 25 4
gpt4 key购买 nike

我的 Restfull Web 服务 metgod 中的 get 方法有问题。我为“我的用户”实体创建一个 Controller ,并且有一个变量 isActive(boolean):isActive 是一个名称,在我的所有代码中,我没有一个简单的 Activity 词,但是当我使用 postman 时,他们返回我:

  {
"userId": 5,
"emailLogin": "t5.email@be-tse.com",
"firstName": "Name_5",
"lastName": "Lastname_5",
"userDepartment": "SALESFORCE",
"roles": [],
"active": false
}

最后一个元素应该是 isActive - 为什么它被改变?我使用 lombok 这可能是一个原因吗?

我的实体:

@Getter
@Setter
@Builder
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "USER")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "USER_ID")
private Integer userId;

@Column(nullable = false, unique = true)
private String emailLogin;

private String firstName;

private String lastName;


@Column(nullable = false)
@JsonIgnore
private String password;

private boolean isActive;

@ManyToOne(optional = false)
@JoinColumn(name = "DEPARTMENT_ID")
@JsonIgnore
private UserDepartment userDepartment;

@ManyToMany
@JsonIgnore
@JoinTable(name = "USER_ROLES",
joinColumns = @JoinColumn(name = "USER_ID"),
inverseJoinColumns = @JoinColumn(name = "ROLE_ID"))
private Set<UserRole> roles;

public User(String emailLogin, String firstName, String lastName, String password, boolean isActive, UserDepartment userDepartment, Set<UserRole> roles) {
this.emailLogin = emailLogin;
this.firstName = firstName;
this.lastName = lastName;
this.password = password;
this.isActive = isActive;
this.userDepartment = userDepartment;
this.roles = roles;
}

}

最佳答案

您必须设置准确的字段名称

@JsonProperty("isActive")
public boolean isActive() {
return isActive;
}

关于java - Rest Get 方法返回不正确的元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54868921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com