JS
function load() {
html = "";
$.ajax({
url: "/blog/ablist",
type: "get",
dataType: "json",
success: function (json) {
console.log(json);
for (var i = 0; i < json.length; i++) {
console.log(json[i].title);
html += "<div class=\"c\" >\n" +
" <div class=\"con\">\n" +
" <div class=\"aftitle\"><a th:href=\"@{/blog/adetail/{id}(id=${'+json[i].id+'})}\" style=\"text-decoration: none;\n" +
" color: black;font-weight:bolder;font-size: large\" th:text=\"${json[i].title}\"><span>"+json[i].title+"</span></a></div><br>\n" +
" <label style=\"font-size: small;color: grey\">作者 : <span th:text=\"${json[i].author}\">"+json[i].author+"</span> </label>\n" +
" <label style=\"font-size: small;color: grey\">时间 :\n" +
" <span th:text=\"${#dates.format(json[i].editTime,'yyyy-MM-dd HH:mm:ss')}\">"+json[i].editTime+"</span> \n" +
" </label>\n" +
" <label style=\"font-size: small;color: grey\">点赞数 : <span th:text=\"${json[i].like}\">"+json[i].liked+"</span> </label>\n" +
" <label style=\"font-size: small;color: grey\">观看数 : <span th:text=\"${json[i].viewed}\">"+json[i].viewed+"</span> </label>\n" +
"<div class=\"con1\">\n" +
" <!-- th:href=\"@{/blog/delete/{id}(id=${blog.id})}\"-->\n" +
" <a id=\"delete\" href=\"/blog/delete/"+json[i].id+"\" th:href=\"@{/blog/delete/{id}(id=${"+json[i].id+"})}\">\n" +
" <button style=\"color: red\">删除</button>\n" +
" </a>\n" +
" <button id=\"lock\">锁定</button>\n" +
" </div>"+
" </div>\n" +
" </div>";
}
$("#content").html(html);
html = "";
}
});
}
下面是后台接受数据
@Transactional
@GetMapping("/delete/{id}")
public String delete(@PathVariable("id") Long id){
blogDao.deleteById(id);
return "redirect:/blog/alist";
}