短评数据加载不出
package com.imooc.reader.controller.management;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.reader.entity.Book;
import com.imooc.reader.entity.Evaluation;
import com.imooc.reader.service.BookService;
import com.imooc.reader.service.EvaluationService;
//import com.imooc.reader.service.UserService;
import com.imooc.reader.service.exception.BussinessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/management/evaluation")
public class MEvaluationController {
@Resource
private EvaluationService evaluationService;
@GetMapping("/index.html")
public ModelAndView showEvaluation(){
return new ModelAndView("/management/evaluation");
}
@GetMapping("/list")
@ResponseBody
public Map list(Integer page , Integer limit){
if(page == null){
page = 1;
}
if(limit == null){
limit = 20;
}
IPage<Evaluation> pageObject = evaluationService.paging( page,limit);
Map result = new HashMap();
result.put("code", "0");
result.put("msg", "success");
result.put("data", pageObject.getRecords());//当前页面数据
result.put("count", pageObject.getTotal());//未分页时记录总数
return result;
}
@PostMapping("/disable")
@ResponseBody
public Map changeState(Long evaluationId, String state){
Map result =new HashMap();
try{
Evaluation rawEvaluation= (Evaluation) evaluationService.selectByEvaluationId(evaluationId);
rawEvaluation.setCreateTime(rawEvaluation.getCreateTime());
rawEvaluation.setEnjoy(rawEvaluation.getEnjoy());
rawEvaluation.setContent(rawEvaluation.getContent());
rawEvaluation.setScore(rawEvaluation.getScore());
rawEvaluation.setBook(rawEvaluation.getBook());
rawEvaluation.setMember(rawEvaluation.getMember());
if(rawEvaluation.getState().equals("enable")){
rawEvaluation.setState("disable");
rawEvaluation.setDisableTime(new Date());
rawEvaluation.setDisableReason(rawEvaluation.getDisableReason());
evaluationService.changeState(evaluationId, null);
result.put("code", "0");
result.put("msg", "success");
} else if (rawEvaluation.getState().equals("disable")) {
rawEvaluation.setState("enable");
}
} catch (BussinessException e) {
e.printStackTrace();
result.put("code",e.getCode());
result.put("msg",e.getMsg());
}
return result;
}
}
前端页面不变 evaluation.ftl:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>短评管理</title>
<style>
#dlgBook{
padding: 10px
}
</style>
<link rel="stylesheet" href="/resources/layui/css/layui.css">
</head>
<body>
<div class="layui-container">
<blockquote class="layui-elem-quote">近期短评列表</blockquote>
<table id="grdEvaluation" lay-filter="grdEvaluation"></table>
</div>
<script src="/resources/layui/layui.all.js"></script>
<script>
var table = layui.table;
var $ = layui.$;
var editor = null;
//第一个实例
table.render({
elem: '#grdEvaluation'
, id : "evaluationList"
, url: "/management/evaluation/list" //数据接口
, page: true //开启分页
, limit :20
, cols: [[ //表头
{field:"createTime" , title: '发布时间', width: '200'}
, {field: 'content', title: '短评', width: '400'}
, {type:"space" ,title: '图书', width: '200', templet: function (d) {
return d.book.bookName;
}}
, {type: "space" , title: '用户名', width: '100', templet: function (d) {
console.info(d);
return d.member.username;
}}
, {type: 'space', title: '操作', width: '100' , templet : function(d){
if(d.state=="enable") {
return "<button class='layui-btn layui-btn-sm ' data-id='" + d.evaluationId + "' onclick='disableEvaluation(this)'>禁用</button>";
}else if(d.state =="disable"){
return "已禁用";
}
}
}
]]
});
function disableEvaluation(obj){
var evaluationId = $(obj).data("id");
layui.layer.prompt({
title: '请输入禁用原因',
},function(value, index, elem){
$.post("/management/evaluation/disable" , {
evaluationId : evaluationId , reason:value
},function(json){
if(json.code=="0"){
layui.layer.close(index);
layui.layer.msg("短评已禁用")
table.reload('evaluationList');
}
} , "json")
});
}
</script>
</body>
</html>
46
收起
正在回答 回答被采纳积分+1
2回答
java工程师2020版
- 参与学习 人
- 提交作业 9401 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星