查询书籍功能

Controller 

package com.kuang.controller;
import com.kuang.pojo.Books;
import com.kuang.service.BooksService;
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.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/book")
public class BooksController {
    //controller 调用 service层
    @Autowired
    @Qualifier("bookServiceImpl")
    private BooksService booksService;
    public void setBooksService(BooksService booksService) {
        this.booksService = booksService;
    }

    //查询全部的书籍,并且返回到一个书籍展示页面
    @RequestMapping("/allBook")
    public  String list(Model model){
        List<Books> list = booksService.findAllBooks();
        model.addAttribute("list",list);

        return "allBook";

    }


}

 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>
<%--   bootstrap美化框架 --%>
    <link  href="https://cdn.staticfile.org/twitter-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>

index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
    <style>

      a{
        text-decoration: none;
        color: black;
        font-size: 18px;

      }

      h3{
        width: 180px;
        height: 38px;
       margin: 100px auto;
        text-align: center;
        line-height: 38px;
        background-color: deepskyblue;
        border-radius: 5px;
      }
    </style>
  </head>
  <body>
    <h3>
      <a href="${pageContext.request.contextPath}/book/allBook">进入到书籍页面</a>
    </h3>
  </body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值