短评数据加载不出

短评数据加载不出

http://img1.sycdn.imooc.com//climg/60f64a8409ec941319130961.jpg

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>​


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕小脸 2021-07-21 17:19:20

同学你好,

1、在MEvaluationController中配置的路径为/management/evaluation,那么在如下路径这里需要添加/evaluation

http://img1.sycdn.imooc.com//climg/60f7e6790962bc2a09030226.jpg

2、这是警告信息,对程序运行没有影响,可忽略不计

祝学习愉快~

  • 提问者 qq_慕神0589333 #1
    上面还有一个提问老师,图书界面也没了
    2021-07-22 16:25:26
  • 好帮手慕小脸 回复 提问者 qq_慕神0589333 #2

    同学你好,图书界面没了,建议同学查看访问路径是否正确,控制台是否有报错呢,在该问答中没有发现同学说的"还有一个提问"是指哪里,建议同学新开问答,将对应的报错以及访问的路径贴出,便于老师测试运行

    祝学习愉快~

    2021-07-22 18:30:51
  • 提问者 qq_慕神0589333 回复 好帮手慕小脸 #3

    http://img1.sycdn.imooc.com//climg/60f950ba09a5cc6b14800761.jpg

    提问者qq_慕神0589333#4

    http://img1.sycdn.imooc.com//climg/60f7e37a092fb7b719120990.jpg

    改了改路径,重新生成out目录后有报错(浏览器)

    jquery.3.3.1.min.js:2 jQuery.Deferred exception: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded
        at String.replace (<anonymous>)
        at Function.htmlPrefilter (http://localhost/resources/jquery.3.3.1.min.js:2:47609)
        at w.fn.init.<anonymous> (http://localhost/resources/jquery.3.3.1.min.js:2:49533)
        at z (http://localhost/resources/jquery.3.3.1.min.js:2:31766)
        at w.fn.init.html (http://localhost/resources/jquery.3.3.1.min.js:2:49344)
        at loadMore (http://localhost/:66:26)
        at loadMore (http://localhost/:72:7)
        at loadMore (http://localhost/:72:7)
        at loadMore (http://localhost/:72:7)
        at loadMore (http://localhost/:72:7) undefined
    w.Deferred.exceptionHook @ jquery.3.3.1.min.js:2
    jquery.3.3.1.min.js:2 Uncaught RangeError: Maximum call stack size exceeded
        at String.replace (<anonymous>)
        at Function.htmlPrefilter (jquery.3.3.1.min.js:2)
        at w.fn.init.<anonymous> (jquery.3.3.1.min.js:2)
        at z (jquery.3.3.1.min.js:2)
        at w.fn.init.html (jquery.3.3.1.min.js:2)
        at loadMore ((index):66)
        at loadMore ((index):72)
        at loadMore ((index):72)
        at loadMore ((index):72)
        at loadMore ((index):72)
    DevTools failed to load source map: Could not load content for http://localhost/resources/bootstrap/bootstrap.min.js.map: Connection error: net::ERR_CONNECTION_REFUSED
    DevTools failed to load source map: Could not load content for http://localhost/resources/bootstrap/bootstrap.css.map: Connection error: net::ERR_CONNECTION_REFUSED


    2021-07-22 19:05:05
好帮手慕小脸 2021-07-20 15:01:04

同学你好,404是访问路径不正确的,同学在MEvaluationController中配置的路径为/management/evaluation,但在访问时路径缺少/evaluation

http://img1.sycdn.imooc.com//climg/60f67476099baf0708200379.jpg

这里建议同学检查自己的左侧导航栏那里的路径引入是否书写错误呢?

祝学习愉快~

  • 提问者 qq_慕神0589333 #1

    改了不行呢

    20:33:34 DEBUG [http-nio-80-exec-7] o.s.w.s.DispatcherServlet - GET "/management/%E7%9F%AD%E8%AF%84%E7%AE%A1%E7%90%86.html", parameters={}
    20:33:34 DEBUG [http-nio-80-exec-7] o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler@5494f478
    20:33:34 DEBUG [http-nio-80-exec-7] o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND

    2021-07-20 21:06:25
  • 好帮手慕小脸 回复 提问者 qq_慕神0589333 #2

    同学你好,贴出的信息并不能看出来问题所在,建议将左侧导航栏那里的路径截图看一下,便于老师检查

    祝学习愉快~

    2021-07-21 09:36:20
  • 提问者 qq_慕神0589333 回复 好帮手慕小脸 #3
    http://img1.sycdn.imooc.com//climg/60f7c676093875f309400249.jpg
    2021-07-21 15:02:16
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师