qq_40669215
2021-03-30 22:08
采纳率: 100%
浏览 74

SpringMVC接收不到form提交的内容

<form action="${pageContext.request.contextPath}/book/submitBook" method="post">
        <div class="form-group">
            <label>书籍名称:</label>
            <input type="text" id="bookName" class="form-control" required>
        </div>
        <div class="form-group">
            <label>书籍数量:</label>
            <input type="text" id="bookCounts" class="form-control" required>
        </div>
        <div class="form-group">
            <label>书籍描述:</label>
            <input type="text" id="detail" class="form-control" required>
        </div>
        <div class="form-group">
            <input type="submit" class="form-control" value="添加">
        </div>

    </form>
package com.kuang.controller;

import com.kuang.pojo.Books;
import com.kuang.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {
    @Autowired
    @Qualifier("BookServiceImpl")
    private BookService bookService;

    @RequestMapping("/allBook")
    public String list(Model model){
        List<Books> books = bookService.queryAll();
        model.addAttribute("list", books);

        return "allBook";
    }

    @RequestMapping("/addBook")
    public String toAddPage(){
        return "addBook";
    }

    @RequestMapping(value = "/submitBook")
    public String addBook(Books books){
        System.out.println("addBook=>" + books);
        bookService.addBook(books);
        return "redirect:/book/allBook";
    }
}

为什么addBook中books内容为空,post和get两种方式都得不到参数

6条回答 默认 最新

相关推荐 更多相似问题