usercontroller.java
@RequestMapping("/listusersjson")
public ResponseEntity<Iterable<User>> getListofUsersJson() {
Iterable<User> users = userService.listUser();
return new ResponseEntity<>(users, HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
user.java
@Entity
public class User {
@Id
@GeneratedValue
@Column(name="user_id")
private Integer id;
private String name;
private String email;
private String password;
private int enabled;
public User(Integer id) {
super();
this.id = id;
}
public User() {
super();
}
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "user_role", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = {
@JoinColumn(name = "role_id") })
@JsonIgnore
private List<Role> roless;
@OneToMany(mappedBy = "user", …Run Code Online (Sandbox Code Playgroud) $(document).ready(function () {
$(".linkDelete").click(function () {
var userid = $(this).attr("id");
console.debug("saurabh userid", userid);
var url = "/delete?id=" + userid;
var s = "SpringHibernateAnnotations";
console.debug("saurabh url", url);
$.ajax({
url: s + "/delete?id=" + userid,
success: function (data) {
$('#result').html(data);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
我有这个jquery ajax函数生成这个URL GET http:// localhost:8080/SpringHibernateAnnotations/SpringHibernateAnnotations/delete?id = 253 404(Not Found)而不是它应该生成 http:// localhost:8080/SpringHibernateAnnotations/delete? id = 253 404,如果我删除var s ="SpringHibernateAnnotations"; 并将我的url保存在ajax方法中作为url:"/ delete?id ="+ userid,它生成http:// localhost:8080/delete?id = 253,因为我无法进入application.So怎么能我生成这个正确的URL http:// localhost:8080/SpringHibernateAnnotations/delete?id = 253