登录后,我自动连接到主页。按下按钮时,我想在 spring boot 中访问控制器上的“findAllUsers”方法,并以表格格式显示注册用户。我为此使用了ajax get call。但是我得到了我在下面的照片中提到的控制台错误。我需要改变什么?我应该怎么办?USER.java@Data@Entity@Table(name = "user")public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_id") private int id; @Column(name = "email") @Email(message = "*Please enter a valid Email") @NotEmpty(message = "*Please provide an email") private String email; @Column(name = "password") @Length(min = 5, message = "*Your password must have at least 5 characters") @NotEmpty(message = "*Please enter your password") private String password; @Column(name = "name") @NotEmpty(message = "*Please enter your name") private String name; @Column(name = "last_name") @NotEmpty(message = "*Please enter your last name") private String lastName; @Column(name = "active") private int active; @ManyToMany(cascade = CascadeType.ALL) @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id")) private Set<Role> roles; //G&S public int getId() { return id; } public void setId(int id) { this.id = id; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getActive() { return active; }
1 回答
梦里花落0921
TA贡献1772条经验 获得超6个赞
注释控制器方法以返回application/json
mime 类型。
@RequestMapping(value="/findAllUsers", method = RequestMethod.GET, produces={ "application/json"}) public List<User> findAllUsers(){ return userService.findAllUsers(); }
添加回答
举报
0/150
提交
取消