• ssm整合——查询书籍功能


    ssm整合:设置查询书籍功能

    BookController.java     编写controller的代码,

    package com.zy.controller;
    
    import com.zy.pojo.Books;
    import com.zy.service.BookService;
    import com.zy.service.BookServiceImpl;
    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 BookController {
        /*controller 层 调用  service层*/
        @Autowired
        @Qualifier("BookServiceImpl")
        private BookService bookService;
    
        /*查询全部的书籍,并且返回到一个书籍展示页面*/
        @RequestMapping("/allBook")
        public String list(Model model){
            List<Books> list = bookService.allbook();
            model.addAttribute("list", list);
            return "allBook";
    
        }
    }

    编写前端代码

    index.jsp 首页

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
      <head>
        <title>首页</title>
        <style>
          h3{
            width: 180px;
            height: 38px;
            margin: 100px auto;
            text-align: center;
            line-height: 38px;
            background: skyblue;
            border-radius: 50px ;
          }
          a{
            text-decoration: none;
            color: black;
            font-size: 18px;
          }
        </style>
      </head>
      <body>
      <h3>
        <a href="${pageContext.request.contextPath}/book/allBook">进入书籍页面</a>
      </h3>
      </body>
    </html>

    allbooks .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>
                        <samp>书籍列表---显示所有书籍</samp>
                    </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>
                    <tbody>
                        <%--书籍从数据库中查询出来,
                            从这个list中遍历出来:foreach--%>
                    <c:forEach var="book" items="${list}">
                        <tr>
                            <td>${book.bookid}</td>
                            <td>${book.bookname}</td>
                            <td>${book.bookcount}</td>
                            <td>${book.dateail}</td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    
    </div>
    
    </body>
    </html>

    显示的结果为

    正在学习中,有错误的地方,请多多指教!
  • 相关阅读:
    一个靠谱的技术方案文档是怎样的
    代码可复用性问题兼谈团队协作
    碎碎念五四
    碎碎念五五
    cmd命令查看本机的端口占用情况
    JS字符串里字符串嵌套和转义字符
    cef内嵌浏览器提示clodop未安装或未启动
    ADD_PRINT_IMAGE直接输出图片URL方式
    lodop缩放图片到完全适合纸张
    部署Kubernetes Cluster
  • 原文地址:https://www.cnblogs.com/16904985zy-aoyu/p/14637817.html
Copyright © 2020-2023  润新知