积极的阿毛
2021-11-17 11:12
采纳率: 0%
浏览 31

RestFul风格写地址,重定向redirect报错


<%--
  Created by IntelliJ IDEA.
  User: 784854876
  Date: 2021/11/12
  Time: 9:17
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>书籍展示</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <div class="page-header">
                        <h1>
                            <small>书籍列表---显示</small>
                        </h1>
                    </div>

                </div>
            </div>

            <div class="row">
                <div class="col-md-4 column">
                    <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddPaper">新增</a>
                    <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/allBook">返回主页</a>
                </div>
                <div class="col-md-4 column"></div>
                <div class="col-md-4 column">
                    <form class="form-inline" action="${pageContext.request.contextPath}/book/searchBook" method="post" style="float:right">
                        <input type="text" name="Search" class="form-control" placeholder="请输入书籍号" required>
                        <input type="submit" value="搜索" class="btn btn-primary">
                    </form>
                </div>
            </div>

            <div class="row clearfix">
                    <div class="col-md-12 column">
                        <table class="table table-hover table-striped">
                            <thead>
                            <tr>
                                <th>书籍信息</th>
                                <th>书籍名称</th>
                                <th>书籍数量</th>
                                <th>书籍详情</th>
                            </tr>
                            </thead>
                        <tbody>
                        <c:forEach var="Books" items="${list}">
                            <tr>
                                <td>${Books.bookID}</td>
                                <td>${Books.bookName}</td>
                                <td>${Books.bookCounts}</td>
                                <td>${Books.detail}</td>
                                <td>
                                    <a href="${pageContext.request.contextPath}/book/update?id=${Books.bookID}" class="btn btn-primary">修改</a>
                                    <a href="${pageContext.request.contextPath}/book/deleteBook/${Books.bookID}" class="btn btn-primary">删除</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                        </table>
                    </div>
            </div>
        </div>
</body>
</html>


    @RequestMapping("/deleteBook/{bookID}")
    public String deleteBook(@PathVariable(bookID) int id){
        bookService.deleteBookById(id);
        return "redirect:allBook";
    }

https://ask.csdn.net/$%7BpageContext.request.contextPath%7D/book/deleteBook/$%7BBooks.bookID%7D
我用RestFul风格写这个删除的 ${pageContext.request.contextPath}地址,返回到Controller中,运行一切正常,Mysql也会删除相应数据
但是 return "redirect:allBook"; 重定向回allBook 一直到 400

16-Nov-2021 20:20:16.787 警告 [http-nio-8080-exec-7] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.logException Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'int'; nested exception is java.lang.NumberFormatException: For input string: "allBook"]

2条回答 默认 最新

相关推荐 更多相似问题