ssm整合查询书籍功能

1.Controller层调用service层

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

    public void setBookService(BookService bookService) {
        this.bookService = bookService;
    }

    @RequestMapping("/all")
    public String AllBook(Model model){
        List<Books> booksList = bookService.queryAllBook();
        model.addAttribute("list",booksList);
        return "allBook";

    }
}

2.index.jsp首页跳转

  <div>
    <a href="${pageContext.request.contextPath}/book/all">查询全部书籍a>
  div>

3.跳转到allBook.jsp进行展示

<%@ 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 href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

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 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>
                    <%--书籍从数据库中查询出来,从这个list中遍历出来:foreach--%>
                    <tbody>
                        <c:forEach var="book" items="${list}">
                            <tr>
                                <td>${book.bookID}td>
                                <td>${book.bookName}td>
                                <td>${book.bookCounts}td>
                                <td>${book.detail}td>
                            tr>
                        c:forEach>

                    tbody>
                table>
            div>
        div>
    div>


body>
html>

可能遇见的问题:
ssm整合查询书籍功能_第1张图片

你可能感兴趣的:(ssm整合)