老师,我的页面为什么会出现这个错误,怎么解决呢?

来源:5-1 图书详情页-读取图书信息

慕仰7036876

2020-07-28 21:27:58

package com.imooc.reader.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.reader.entity.Book;

public interface BookService {
    /**
     * 分页查询图书
     * @param categoryId 分类Id
     * @param order 排序方式
     * @param page 页号
     * @param rows 每页记录数
     * @return 分页对象
     */
    public IPage<Book> paging(Long categoryId, String order, Integer page, Integer rows);

    /**
     * 根据图书编号查询图书对象
     * @param bookId 图书编号
     * @return 图书对象
     */
    public Book selectById(Long bookId);
}
package com.imooc.reader.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imooc.reader.entity.Book;
import com.imooc.reader.mapper.BookMapper;
import com.imooc.reader.service.BookService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Service("bookService")
@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;
    @Resource
    private BookService bookService;
    //此为接口实现类
    public IPage<Book> paging(Long categoryId, String order, Integer page, Integer rows) {
        Page<Book> p = new Page<Book>(page, rows);
        QueryWrapper<Book> queryWrapper = new QueryWrapper<Book>();
        if(categoryId != null && categoryId != -1){
            queryWrapper.eq("category_id", categoryId);
        }
        if(order != null){
            if(order.equals("quantity")){
                queryWrapper.orderByDesc("evaluation_quantity");
            }else if(order.equals("score")){
                queryWrapper.orderByDesc("evaluation_score");
            }
        }
        IPage<Book> pageObject = bookMapper.selectPage(p, queryWrapper);
        return pageObject;
    }

    /**
     * 根据图书编号查询图书对象
     * @param bookId 图书编号
     * @return 图书对象
     */
    public Book selectById(Long bookId){
        Book book = bookMapper.selectById(bookId);
        return book;
    }

}
package com.imooc.reader.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

@TableName("book")
public class Book {
    @TableId(type = IdType.AUTO)
    private Long bookId;
    private String bookName;
    private String subTitle;
    private String author;
    private String cover;
    private String description;
    private Long categoryId;
    private Float evaluationScore;
    private Integer evaluationQuantity;

    public Book(){

    }

    public Book(Long bookId, String bookName, String subTitle, String author, String cover, String description, Long categoryId, Float evaluationScore, Integer evaluationQuantity) {
        this.bookId = bookId;
        this.bookName = bookName;
        this.subTitle = subTitle;
        this.author = author;
        this.cover = cover;
        this.description = description;
        this.categoryId = categoryId;
        this.evaluationScore = evaluationScore;
        this.evaluationQuantity = evaluationQuantity;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    public String getSubTitle() {
        return subTitle;
    }

    public void setSubTitle(String subTitle) {
        this.subTitle = subTitle;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Long categoryId) {
        this.categoryId = categoryId;
    }

    public Float getEvaluationScore() {
        return evaluationScore;
    }

    public void setEvaluationScore(Float evaluationScore) {
        this.evaluationScore = evaluationScore;
    }

    public Integer getEvaluationQuantity() {
        return evaluationQuantity;
    }

    public void setEvaluationQuantity(Integer evaluationQuantity) {
        this.evaluationQuantity = evaluationQuantity;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    @Override
    public String toString() {
        return "Book{" +
                "bookId=" + bookId +
                ", bookName='" + bookName + '\'' +
                ", subTitle='" + subTitle + '\'' +
                ", author='" + author + '\'' +
                ", cover='" + cover + '\'' +
                ", description='" + description + '\'' +
                ", categoryId=" + categoryId +
                ", evaluationScore=" + evaluationScore +
                ", evaluationQuantity=" + evaluationQuantity +
                '}';
    }
}
package com.imooc.reader.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.imooc.reader.entity.Book;

public interface BookMapper extends BaseMapper<Book> {

}
package com.imooc.reader.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.reader.entity.Book;
import com.imooc.reader.entity.Category;
import com.imooc.reader.service.BookService;
import com.imooc.reader.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class BookController {
    @Resource
    private CategoryService categoryService;
    @Resource
    private BookService bookService;
    /**
     * 显示首页
     * @return
     */
    @GetMapping("/")
    public ModelAndView showIndex(){
        ModelAndView mav = new ModelAndView("/index");
        List<Category> categoryList = categoryService.selectAll();
        mav.addObject("categoryList", categoryList);
        return mav;
    }

    /**
     * 分页查询图书列表
     * @param p 页号
     * @return 分页对象
     */
    @GetMapping("/books")
    @ResponseBody
    public IPage<Book> selectBook(Long categoryId, String order, Integer p){
        if(p == null){
            p = 1;
        }
        IPage<Book> pageObject =  bookService.paging(categoryId, order, p, 10);
        return pageObject;
    }

    @GetMapping("/book/{id}")
    public ModelAndView showDetail(@PathVariable("id") Long id){
        Book book = bookService.selectById(id);
        ModelAndView mav = new ModelAndView("/detail");
        mav.addObject("book", book);
        return mav;
    }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>${book.bookName}</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="/resources/bootstrap/bootstrap.css">
    <link rel="stylesheet" href="/resources/raty/lib/jquery.raty.css">
    <script src="/resources/jquery.3.3.1.min.js"></script>
    <script src="/resources/bootstrap/bootstrap.min.js"></script>
    <script src="/resources/art-template.js"></script>
    <script src="/resources/raty/lib/jquery.raty.js"></script>
    <style>
        .container {
            padding: 0px;
            margin: 0px;
        }

        .row {
            padding: 0px;
            margin: 0px;
        }

        .alert {
            padding-left: 0.5rem;
            padding-right: 0.5rem;
        }

        .col- * {
            padding: 0px;
        }

        .description p {
            text-indent: 2em;
        }

        .description img {
            width: 100%;
        }

        .highlight {
            background-color: lightskyblue !important;
        }

    </style>
    <script>
        $.fn.raty.defaults.path = './resources/raty/lib/images';
        $(function () {
            $(".stars").raty({readOnly: true});
        })
    </script>
</head>
<body>
<!--<div style="width: 375px;margin-left: auto;margin-right: auto;">-->
<div class="container ">
    <nav class="navbar navbar-light bg-white shadow mr-auto">
        <ul class="nav">
            <li class="nav-item">
                <a href="/">
                    <img src="https://m.imooc.com/static/wap/static/common/img/logo2.png"  class="mt-1"
                         style="width: 100px">
                </a>
            </li>

        </ul>
    </nav>


    <div class="container mt-2 p-2 m-0" style="background-color:rgb(127, 125, 121)">
        <div class="row">
            <div class="col-4 mb-2 pl-0 pr-0">
                <img style="width: 110px;height: 160px"
                     src="${book.cover}">
            </div>
            <div class="col-8 pt-2 mb-2 pl-0">
                <h6 class="text-white">${book.bookName}</h6>
                <div class="p-1 alert alert-warning small" role="alert">
                    ${book.subTitle}
                </div>
                <p class="mb-1">
                    <span class="text-white-50 small">${book.author}</span>
                </p>
                <div class="row pl-1 pr-2">
                    <div class="col-6 p-1">
                        <button type="button" data-read-state="1" class="btn btn-light btn-sm w-100">
                            <img style="width: 1rem;" class="mr-1"
                                 src="https://img3.doubanio.com/f/talion/cf2ab22e9cbc28a2c43de53e39fce7fbc93131d1/pics/card/ic_mark_todo_s.png"/>想看
                        </button>
                    </div>
                    <div class="col-6 p-1">
                        <button type="button" data-read-state="2" class="btn btn-light btn-sm  w-100">
                            <img style="width: 1rem;" class="mr-1"
                                 src="https://img3.doubanio.com/f/talion/78fc5f5f93ba22451fd7ab36836006cb9cc476ea/pics/card/ic_mark_done_s.png"/>看过
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="row" style="background-color: rgba(0,0,0,0.1);">
            <div class="col-2"><h2 class="text-white">${book.evaluationScore}</h2></div>
            <div class="col-5 pt-2">
                <span class="stars" data-score="${book.evaluationScore}"></span>
            </div>
            <div class="col-5  pt-2"><h5 class="text-white">${book.evaluationQuantity}人已评</h5></div>
        </div>
    </div>
    <div class="row p-2 description">
        ${book.description}
    </div>


    <div class="alert alert-primary w-100 mt-2" role="alert">短评
        <button type="button" id="btnEvaluation" class="btn btn-success btn-sm text-white float-right"
                style="margin-top: -3px;">
            写短评
        </button>
    </div>
    <div class="reply pl-2 pr-2">
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-126</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="41"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>33</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    很好的教程,内容写的也比较有深度,值得推荐。
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-120</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="42"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>24</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    感谢慕课网提供这么好的内容
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-28</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="43"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>47</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    网上大神推荐的内容,有空看下
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-435</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="44"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>0</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    我很喜欢,内容精典,值得收藏,推荐阅读
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-24</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="45"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>21</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    活动买的很划算,作为开发的工具书真的是很好
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-476</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="46"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>12</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    很好的教程,干货很多,对我的帮助非常大。
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-118</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="47"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>33</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    慕课出品,值得信赖,很喜欢
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-323</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="48"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>33</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    非常好的教程,对自己的提升很大,面向工资编程,奥力给!
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-184</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="49"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>48</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    给老公买的说很好用。
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-397</span>
                    <span class="stars mr-2" data-score="4"></span>

                    <button type="button" data-evaluation-id="50"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>19</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    别人推荐的,希望有所帮助。一直信赖慕课
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-23</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="51"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>6</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    很不错啊,一直很信赖慕课网的品质,希望慕课网越做越好!
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-334</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="52"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>22</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    非常棒,之前已经看过,现在是二刷
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-410</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="53"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>8</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    正在看,内容很简洁,容易明白!
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-247</span>
                    <span class="stars mr-2" data-score="5"></span>

                    <button type="button" data-evaluation-id="54"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>37</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    慕课网的售后服务超级给力!
                </div>
                <hr/>
            </div>
            <div>
                <div>
                    <span class="pt-1 small text-black-50 mr-2">05-24</span>
                    <span class="mr-2 small pt-1">慕粉-441</span>
                    <span class="stars mr-2" data-score="4"></span>

                    <button type="button" data-evaluation-id="55"
                            class="btn btn-success btn-sm text-white float-right" style="margin-top: -3px;">
                        <img style="width: 24px;margin-top: -5px;" class="mr-1"
                             src="https://img3.doubanio.com/f/talion/7a0756b3b6e67b59ea88653bc0cfa14f61ff219d/pics/card/ic_like_gray.svg"/>
                        <span>21</span>
                    </button>
                </div>

                <div class="row mt-2 small mb-3">
                    很不错的教程,讲的很详细
                </div>
                <hr/>
            </div>
    </div>
</div>


<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
     aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-body">
                您需要登录才可以操作哦~
            </div>
            <div class="modal-footer">
                <a href="/login.html" type="button" class="btn btn-primary">去登录</a>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="dlgEvaluation" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
     aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <h6>为"从 0 开始学爬虫"写短评</h6>
                <form id="frmEvaluation">
                    <div class="input-group  mt-2 ">
                        <span id="score"></span>
                    </div>
                    <div class="input-group  mt-2 ">
                        <input type="text" id="content" name="content" class="form-control p-4" placeholder="这里输入短评">
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" id="btnSubmit" class="btn btn-primary">提交</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>

http://img.mukewang.com/climg/5f2027bc0914d36c18700945.jpg

写回答

1回答

好帮手慕小班

2020-07-29

同学你好,1、根据报错信息,Could not  resolve  view  with name '/detail' in servlet with name 'springmvc'-->无法在名为springmvc的servlet中解析名为“/detail”的视图。

同学在自己项目中是否有正确的detail页面呐,比如:

http://img.mukewang.com/climg/5f20dff509cbccfa03540450.jpg

    2、检查测试这里的跳转代码并没有问题,所以在Controller中的代码书写没有问题。

http://img.mukewang.com/climg/5f20e0e10925ab0f05230174.jpg

继续加油!祝学习愉快!

1

0 学习 · 16556 问题

查看课程