关于 spring boot rest api 和 javascript ajax 调用通信的问题

登录后,我自动连接到主页。按下按钮时,我想在 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;

    }



杨__羊羊
浏览 131回答 1
1回答

梦里花落0921

注释控制器方法以返回application/jsonmime 类型。@RequestMapping(value="/findAllUsers",&nbsp;method&nbsp;=&nbsp;RequestMethod.GET,&nbsp;produces={&nbsp;"application/json"}) &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;List<User>&nbsp;findAllUsers(){&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;userService.findAllUsers(); &nbsp;&nbsp;&nbsp;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java