页面运行失败

页面运行失败


相关代码:

package com.imooc.reader.controller.management;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.reader.entity.Evaluation;
import com.imooc.reader.service.EvaluationService;
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("/evaluation.html")
    public ModelAndView showEvaluation(){
        return new ModelAndView("/management/evaluation");
    }
    @GetMapping("/list")
    @ResponseBody
    public Map list(Integer page, Integer rows){
        Map result=new HashMap();
        if(page==null){
            page=1;
        }
        if(rows==null){
            rows=20;
        }
        IPage<Evaluation> evaluationIPage=evaluationService.list(page,rows);
        result.put("code","0");
        result.put("data",evaluationIPage.getRecords());
        result.put("message","");
        return result;
    }
    @PostMapping("/disable")
    @ResponseBody
    public Map UpdateState(Evaluation evaluation){
        Map result=new HashMap();
        try {
            Evaluation rawEvaluation = evaluationService.updateState(evaluation);
            rawEvaluation.setState("disable");
            rawEvaluation.setDisableReason(evaluation.getDisableReason());
            rawEvaluation.setDisableTime(new Date());
            evaluationService.updateState(rawEvaluation);
        }catch(BussinessException ex){
            ex.printStackTrace();
            result.put("code",ex.getCode());
            result.put("msg",ex.getMsg());
        }
        return  result;
    }
}

相关代码:

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

相关代码:

package com.imooc.reader.controller.management;

import com.imooc.reader.entity.User;
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 javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/management/user")
public class MUserController {
    @Resource
    private UserService userService;
    @GetMapping("/login.html")
    public ModelAndView showLogin(){
        return new ModelAndView("/management/login");
    }
    @PostMapping("/check_login")
    @ResponseBody
    public Map checklogin(String username,String password,HttpSession session){
        Map result=new HashMap();
        try {
            User user = userService.checklogin(username,password);
            session.setAttribute("loginUser",user);
            result.put("code", "0");
            result.put("msg", "success");
            result.put("redirect_url","/management/index.html");
        }catch(BussinessException ex){
            ex.printStackTrace();
            result.put("code",ex.getCode());
            result.put("msg",ex.getMsg());
        }
        return  result;
    }
}

相关代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图书管理系统</title>
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
    <style>
        body{
            background-color: #F2F2F2;
        }
        .oa-container{
            /*background-color: white;*/
            position: absolute;
            width: 400px;
            height: 350px;
            top: 50%;
            left: 50%;
            padding: 20px;
            margin-left: -200px;
            margin-top: -175px;
        }
        #username,#password{
            text-align: center;
            font-size: 24px;
        }
    </style>
</head>
<body>
<div class="oa-container">
    <h1 style="text-align: center;margin-bottom: 20px">图书管理系统</h1>
    <form class="layui-form">
        <div class="layui-form-item">
            <input type="text" id="username" lay-verify="required" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input" >
        </div>

        <div class="layui-form-item">
            <input type="password" id="password" lay-verify="required" name="password" placeholder="请输入密码" autocomplete="off" class="layui-input" >
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
        </div>
    </form>
</div>
<script src="/resources/layui/layui.all.js"></script>
<script>
    // 表单提交事件
    layui.form.on("submit(login)" , function(formdata){//data参数包含了当前表单的数据
        console.log(formdata);
        //发送ajax请求进行登录校验
        layui.$.ajax({
            url : "/management/user/check_login",
            data : formdata.field, //提交表单数据
            type : "post",
            dataType : "json" ,
            success : function(json){
                console.log(json);
                if(json.code == "0"){ //登录校验成功
                    //layui.layer.msg("登录成功");
                    //跳转url
                    window.location.href=json.redirect_url;
                }else{
                    layui.layer.msg(json.message);
                }
            }
        })
        return false;//submit提交事件返回true则表单提交,false则阻止表单提交
    })
</script>
</body>
</html>


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

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

1回答
好帮手慕小脸 2021-04-24 13:55:26

同学你好,建议同学具体描述一下“页面运行失败”是指哪里?便于老师定位问题

祝学习愉快~

  • 提问者 PAN_WAN_TING #1

    后台登录以及短评管理都运行不上?
    GetMapping和PostMpping绑定不是很清楚。麻烦给指导一下。感谢!

    2021-04-24 14:21:39
  • 好帮手慕小脸 回复 提问者 PAN_WAN_TING #2

    同学你好,

    1、老师这边是可以正确访问,建议同学描述一下“后台登录以及短评管理都运行不上”是指访问报错吗?如果是报错,建议将报错贴出

    2、@GetMapping 是限定使用get请求的时候,在请求访问时,直接在浏览器地址栏中进行请求,访问的方式是get

    @PostMapping是限定使用post请求的时候 ,用于将Http post请求映射到特定处理程序的方法注解

    祝学习愉快~

    2021-04-24 17:10:34
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

在线咨询

领取优惠

免费试听

领取大纲

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