javaEE SSM framework maven project introduction simple book management - Novice final review
#This project is only used for novice reference and entry reference to realize super simple login registration and book search, poor selection, deletion and modification. Please detour, Daniel. The first article is dedicated to java (the regret of the front-end people)
1. Configuration file
1. jdbc.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/test jdbc.username=root jdbc.password=123456 jdbc.maxTotal=30 jdbc.maxIdle=10 jdbc.initialSize=5
2.mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <typeAliases> <package name="com.lsnu.demo.domain"></package> </typeAliases> <mappers> <package name="com.lsnu.demo.mapper"></package> </mappers> </configuration>
3.log4j.properties
# Global logging configuration log4j.rootLogger=ERROR, stdout # MyBatis logging configuration... log4j.logger.com.lsnu.cross.mapper=DEBUG #The path here should be changed to the path of the corresponding mapper file # Console output... log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
4.springmvc-config.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!--controller annotation--> <context:component-scan base-package="demo.controller"></context:component-scan> <!-- Spring MVC Annotation driven support --> <mvc:annotation-driven></mvc:annotation-driven> <!-- Prefix directory and suffix file name configuration of front-end view parser --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp"></property> <property name="suffix" value=".jsp"></property> </bean> <!--Configure the access mapping of static resources. The files in this configuration will not be intercepted by the front-end controller --> <mvc:resources mapping="/static/**" location="/static/"></mvc:resources> <!--Solve garbled code--> <bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="UTF-8"></property> <property name="maxUploadSize" value="1048576600"></property> </bean> <!--Interceptor--> </beans>
5.applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd"> <!--read db.properties--> <context:property-placeholder location="classpath:db.properties"></context:property-placeholder> <!--Configure data sources--> <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"> <!--Data driven--> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <!--link url--> <property name="url" value="jdbc:mysql://localhost:3306/test"></property> <!--Connection user name--> <property name="username" value="root"></property> <!--connect mima--> <property name="password" value="123456"></property> <!--connect zuidashu--> <property name="maxTotal" value="30"></property> <!--Connection maximum idle--> <property name="maxIdle" value="10"></property> <!--Number of connection initialization connections--> <property name="initialSize" value="5"></property> </bean> <!--Transaction management depends on the data source--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!--Injection data source--> <property name="dataSource" ref="dataSource"></property> </bean> <!-- Open transaction annotation --> <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> <!-- to configure mybatis factory SqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!--Injection data source--> <property name="dataSource" ref="dataSource"></property> <!--appoint mybatis file--> <property name="configLocation" value="classpath:mybatis-config.xml"></property> </bean> <!-- to configure mapper Scanner --> <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.lsnu.demo.mapper"></property> </bean> <!-- scanning Service --> <context:component-scan base-package="demo.service"></context:component-scan> </beans>
2.Main file
directory structure ![main File structure style](https://img-blog.csdnimg.cn/a6095be68c11439cb6c3ee8c1c7098bb.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBATU9BTi4=,size_17,color_FFFFFF,t_70,g_se,x_16) Start writing java Code under file( jaava Below com.lsnu.demo File name (change according to the needs of the project)
1. First write the domain (equivalent to pojo) file
First in domain Create the required entity class and create the corresponding class Documents, such as this simple library management project, need to be used User and Book Two entity classes User getter,setter,ToString Parametric construction and nonparametric construction can be realized through generate(IDEA)One click generation
package com.lsnu.demo.domain; import lombok.Data; import lombok.ToString; @Data @ToString public class User { private Integer userId; private String userName; private String password; private String email; public User() { super(); } public User(Integer userId, String userName, String password, String email) { this.userId = userId; this.userName = userName; this.password = password; this.email = email; } public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } @Override public String toString() { return "User{" + "userId=" + userId + ", userName='" + userName + '\'' + ", password='" + password + '\'' + ", email='" + email + '\'' + '}'; } }
Book
I suggest you kiss the realization of one function
package com.lsnu.demo.domain; import lombok.Data; import lombok.ToString; @Data @ToString public class Book { private int bookid; private String bookname; private double price; public int getBookid() { return bookid; } public void setBookid(int bookid) { this.bookid = bookid; } public String getBookname() { return bookname; } public void setBookname(String bookname) { this.bookname = bookname; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Book(int bookid, String bookname, double price) { this.bookid = bookid; this.bookname = bookname; this.price = price; } @Override public String toString() { return "Book{" + "bookid=" + bookid + ", bookname='" + bookname + '\'' + ", price=" + price + '}'; } }
2. Next, write the code in mapper
First of all, mapper can operate data on the database. The mapper file corresponding to each entity class is composed of an Iterface and an xml file. The required methods are written in the interface file, and the operations on the database are written in the xml file
UserMapper
package com.lsnu.demo.mapper; import com.lsnu.demo.domain.User; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import java.util.List; public interface UserMapper { User login(String username,String password); int register(User user); }
UserMapper.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.lsnu.demo.mapper.UserMapper"> <select id="login" parameterType="String" > select * from user where user_name = #{userName} and password = #{password} </select> <insert id="register" parameterType="com.lsnu.demo.domain.User"> insert into user(userId,user_name,password) values (#{userId},#{userName},#{password}) </insert> </mapper>
3.BookMapper
package com.lsnu.demo.mapper; import com.lsnu.demo.domain.Book; import org.apache.ibatis.session.RowBounds; import org.springframework.stereotype.Repository; import java.util.List; @Repository public interface BookMapper { // Find all books // Find by id // Find by name // add to // delete // to update public List<Book> getAllBooks(); public List<Book> queryByBookid(int bookid); public List<Book> queryByBookname(String bookname); public int addBook(Book book); public int delBook(int bookid); public int updateBook(Book book); public int save(Book book); }
BookMapper.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.lsnu.demo.mapper.BookMapper"> <!--Query all books--> <select id="findAllBooks" resultType="com.lsnu.demo.domain.Book"> select * from book </select> <!--adopt id query--> <select id="queryByBookid" resultType="com.lsnu.demo.domain.Book" parameterType="Integer" > select * from book where bookid=#{bookid} </select> <!--Fuzzy query by book title--> <select id="queryByBookid" resultType="com.lsnu.demo.domain.Book" parameterType="String" > select * from book where bookname like concat('%',#{bookname},'%') </select> <insert id="addBook" parameterType="com.lsnu.demo.domain.Book" > insert into book(bookname,price) values (#{bookname},#{price}) </insert> <delete id="delBook" parameterType="Integer"> delete from book where bookid=#{bookid} </delete> <update id="updateBook" parameterType="com.lsnu.demo.domain.Book" > update book set bookname=#{bookname},pirce = #{price} where bookid = #{bookid} </update> <insert id="save" parameterType="Book" > insert into book(bookname,price) values (#{bookname},#{price}) </insert> </mapper>
4. Write the Service layer again
Each entity class in Service also corresponds to an interface file and an implementation class
UserService(Iterface)
package com.lsnu.demo.service; import com.lsnu.demo.domain.User; public interface UserService { User login(String username,String password); int register(User user); }
UserMapperImpl(class)
package com.lsnu.demo.service; import com.lsnu.demo.domain.Book; import com.lsnu.demo.mapper.BookMapper; import org.apache.ibatis.session.RowBounds; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service @Transactional public class BookServiceImpl implements BookService{ @Autowired BookMapper bookMapper; @Override public List<Book> getAllBooks() { return bookMapper.getAllBooks(); } @Override public List<Book> queryByBookid(int bookid) { return bookMapper.queryByBookid(bookid); } @Override public List<Book> queryByBookname(String bookname) { return bookMapper.queryByBookname(bookname); } @Override public int addBook(Book book) { return bookMapper.addBook(book); } @Override public int delBook(int bookid) { return bookMapper.delBook(bookid); } @Override public int updateBook(Book book) { return bookMapper.updateBook(book); } @Override public List<Book> selectAuthors() { return bookMapper.selectAuthors(); } @Override public List<Book> selectAuthors(RowBounds rowBounds) { return bookMapper.selectAuthors(rowBounds); }
BookService(Iterface)
package com.lsnu.demo.service; import com.lsnu.demo.domain.Book; import org.apache.ibatis.session.RowBounds; import java.util.List; public interface BookService { public List<Book> getAllBooks(); public List<Book> queryByBookid(int bookid); public List<Book> queryByBookname(String bookname); public int addBook(Book book); public int delBook(int bookid); public int updateBook(Book book); List<Book> selectAuthors(); List<Book> selectAuthors(RowBounds rowBounds); int getCount(); }
BookServiceImpl(class)
package com.lsnu.demo.service; import com.lsnu.demo.service.Page; import com.lsnu.demo.domain.Book; import com.lsnu.demo.mapper.BookMapper; import org.apache.ibatis.session.RowBounds; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service @Transactional public class BookServiceImpl implements BookService{ @Autowired BookMapper bookMapper; @Override public List<Book> getAllBooks() { return bookMapper.getAllBooks(); } @Override public List<Book> queryByBookid(int bookid) { return bookMapper.queryByBookid(bookid); } @Override public List<Book> queryByBookname(String bookname) { return bookMapper.queryByBookname(bookname); } @Override public int addBook(Book book) { return bookMapper.addBook(book); } @Override public int delBook(int bookid) { return bookMapper.delBook(bookid); } @Override public int updateBook(Book book) { return bookMapper.updateBook(book); } @Override public List<Book> selectAuthors() { return bookMapper.selectAuthors(); } @Override public List<Book> selectAuthors(RowBounds rowBounds) { return bookMapper.selectAuthors(rowBounds); } @Override public int getCount() { return 0; } public Page<Book> findPage(Integer pageNo,Integer pageSize){ int count = bookMapper.getCount(); if(pageNo == null || pageNo <= 1) pageNo=1; if(pageSize==null) pageSize=5; int pageCount = Integer.parseInt(String.valueOf(count/pageSize)); if(pageCount<pageNo) pageNo=pageCount; Integer start = (pageNo-1)*pageSize; if(start<0) start=0; RowBounds rowBounds = new RowBounds(start,pageSize); List<Book> books=bookMapper.selectAuthors(rowBounds); Page<Book> page = new Page<Book>(); page.setPageNo(pageNo); page.setResults(books); page.setTotal(count); return page; } }
5.Controller layer
UserController
package com.lsnu.demo.controller; import com.lsnu.demo.domain.User; import com.lsnu.demo.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import javax.jws.WebParam; import javax.servlet.http.HttpSession; @Controller @RequestMapping("/user") public class userController { @Autowired UserService userService; @RequestMapping("/login") public String login(User user, Model model, HttpSession session){ //Get user name and password String username =user.getUserName(); String userPassword=user.getPassword(); //judge if(username != null && userPassword != null){ User user1 = userService.login(username,userPassword); session.setAttribute("user",user1.getUserName()); return "redirect:/book/getAllBook"; } model.addAttribute("msg","User name or password is empty"); return "redirect:/book/getAllBook"; } @RequestMapping("/register") public String register(User u, Model model){ int result = userService.register(u); model.addAttribute("msg","login was successful"); return "login"; } }
BookController
package com.lsnu.demo.controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.lsnu.demo.domain.Book; import com.lsnu.demo.service.BookService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @Controller @RequestMapping("/book") public class BookController { @Autowired BookService bookService; @RequestMapping("/getAllBooks") public String findAllBooks(Model model, @RequestParam(defaultValue = "1") int pageNo,@RequestParam(defaultValue = "5")int pageSize){ PageHelper.startPage(pageNo,pageSize); List<Book> book = bookService.getAllBooks(); PageInfo<Book> p = new PageInfo<Book>(book); model.addAttribute( "booklist",book); model.addAttribute("pageInfo",p); return "bookInfo"; } @RequestMapping("/queryById") public String queryById(int bookid,Model model, @RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "5")int pageSize){ if(pageNum == 0) pageNum = 1; PageHelper.startPage(pageNum,pageSize); List<Book> book = bookService.queryByBookid(bookid); PageInfo<Book> p = new PageInfo<Book>(book); model.addAttribute( "booklist",book); model.addAttribute("pageInfo",p); model.addAttribute("bookid",bookid); return "queryInfoById"; } @RequestMapping("/queryByNmme") public String queryByName(String name,Model model, @RequestParam(defaultValue = "1") int pageNo,@RequestParam(defaultValue = "5")int pageSize){ if(pageNo == 0) pageNo = 1; PageHelper.startPage(pageNo,pageSize); List<Book> book = bookService.queryByBookname(name); PageInfo<Book> p = new PageInfo<Book>(book); model.addAttribute( "booklist",book); model.addAttribute("pageInfo",p); model.addAttribute("bookname",name); return "queryInfoByName"; } @RequestMapping("/delBook") public String delBook(int bookid,Model model){ int res = bookService.delBook(bookid); if(res > 0){ return "forword:findAllBooks"; }else { model.addAttribute("msg","Deletion failed!"); return "bookInfo"; } } @RequestMapping("/toAddBook") public String toAddBook(){return "addBook";}; @RequestMapping("/addBook") public String addBook(Book book,Model model){ int res = bookService.addBook(book); if(res > 0){ return "forword:findAllBooks"; }else { model.addAttribute("msg","Failed to add!"); return "bookInfo"; } } @RequestMapping("/toupdateBook") public String toUpdateBook(){return "updateBook";}; @RequestMapping("/updateBook") public String updateBook(Book book,Model model){ int res = bookService.updateBook(book); if(res > 0){ return "forword:findAllBooks"; }else { model.addAttribute("msg","Update failed!"); return "bookInfo"; } } }
3.Jsp page
Finally, just write the jsp file, and then create two folders under the WEB-INF to store the jsp file and the imported jq and bootstrap files
1.login.jsp
Don't forget to import external css styles and js files. You can use cdn links or import locally. The css styles of this project are imported from the official bootstrap website
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <html> <head> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> <title>User login</title> </head> <body> <form action="${pageContext.request.contextPath}/user/login" method="post"> <div class="form-group"> <label for="exampleInputEmail1">user name</label> <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="username"> </div> <div class="form-group"> <label for="exampleInputPassword1">password</label> <input type="password" class="form-control" id="exampleInputPassword1"> </div> <button type="submit" class="btn btn-primary">land</button> <a class="btn btn-primary" href="#"Role =" button "id =" register "> register</a> </form> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> <script> var regis = document.querySelector("#regist"); regis.addEventListener("click",function (evt) { window.location.href="regist.jsp" }) </script> </html>
2.regist.jsp
Similar to login
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <html> <head> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> <title>User registration</title> </head> <body> <form action="${pageContext.request.contextPath}/user/register" method="post"> <div class="form-group"> <label for="exampleInputEmail1">user name</label> <input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" name="username"> </div> <div class="form-group"> <label for="exampleInputPassword1">password</label> <input type="password" class="form-control" id="exampleInputPassword1"> </div> <button type="submit" class="btn btn-primary" id="login">land</button> <a class="btn btn-primary" href="#"Role =" button "id =" register "> register</a> </form> </body> <script src="${pageContext.request.contextPath}/static/css/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/css/jquery-1.11.3.min.js"></script> <script> var login = document.querySelector("#login"); login.addEventListener("click",function (evt) { window.location.href="login.jsp" }) </script> </html>
3.bookInfo.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> <title>Title</title> </head> <body> Welcome,<%=session.getAttribute("user")%>> ${msg} <center> <form method="post" action="${pageContext.request.contextPath}/book/queryByNmme"> <input type="text" name="name" placeholder="Please enter keyword query"/> <input type="submit" value="Submit"/> <a href="${pageContext.request.contextPath}/book/toAddBook">add to</a> </form><br> <form method="post" action="${pageContext.request.contextPath}/book/queryById"> <input type="text" name="bookid" placeholder="Please enter the book number for inquiry"/> <input type="submit" value="Submit"/> </form><br> <table border="1px" width="500px"> <tr> <th>number</th> <th>title</th> <th>Price</th> <th>operation</th> </tr> <c:choose> <c:when test="${ empty booklist} " > <tr><td>No relevant information found!</td></tr> </c:when> <c:otherwise> <c:forEach items="${booklist}" var="x"> <tr> <td style="text-align: center;">${x.bookid}</td> <td style="text-align: center;">${x.name}</td> <td style="text-align: center;">${x.price}</td> <td style="text-align: center;"> <a href="${pageContext.request.contextPath}/book/toupdateBook">modify</a>/ <a href="${pageContext.request.contextPath}/book/delBook?bookid=${x.bookid}">delete</a></td> </tr> </c:forEach> </c:otherwise> </c:choose> </table> The first ${pageinfo.pageNum }page/common ${pageinfo.pages}page<br> <a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.prePage}">previous page</a> <c:forEach begin="1" end="${pageinfo.pages}" step="1" var="y" items="pageInfo"> <a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${y}">${y}</a> </c:forEach> <a href="${pageContext.request.contextPath }/book/getAllBook?pageNum=${pageinfo.nextPage}">next page</a> </center> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> </html>
4.addBook.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> <title>Add books</title> </head> <body> <form action="${pageContext.request.contextPath}/book/addBook" method="post"> title:<input type="text" name="name" /><br> Price:<input type="text" name="price" /><br><br> <input type="submit" value="Submit" /><br> </form> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> </html>
updateBook.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> <title>Update books</title> </head> <body> <form action="${pageContext.request.contextPath}/book/updateBook" method="post"> No.:<input type="text" name="bookid" value="<%=request.getParameter("bookid")%>" readonly="readonly"/><br> title:<input type="text" name="name" /><br> Price:<input type="text" name="price" /><br><br> <input type="submit" value="Submit" /><br> </form> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> </html>
5.queryInfoById.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>according to ID Find books</title> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> </head> <body> <a href="bookInfo.jsp">To return to the main page, click</a> <table class="table"> <thead> <tr> <th scope="col">bookId</th> <th scope="col">bookName</th> <th scope="col">bookPrice</th> <th scope="col">operation</th> </tr> </thead> <tbody> <c:forEach items="${booklist}" var="book"> <tr> <th scope="row">${book.bookid}</th> <td>${book.bookname}</td> <td>${book.price}</td> <td> <a href="${pageContext.request.contextPath}/book/toupdateBook">modify</a> <a href="${pageContext.request.contextPath}/book/delBook?bookid=${book.bookid}">delete</a> </td> </tr> </c:forEach> <nav aria-label="Page navigation example"> <ul class="pagination"> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/book/queryById?pageNum=${pageInfo.prePage}" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <c:forEach items="${pageInfo}" var="p" begin="1" end="${pageInfo.pages}" step="1"> <li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/book/queryById?pageNum=${p}">${p}</a></li> </c:forEach> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/book/queryById?pageNum=${pageInfo.nextPage}" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav> </tbody> </table> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> </html>
queryInfoByName.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <html> <head> <title>according to ID Find books</title> <link rel="${pageContext.request.contextPath}/static/css/bootstrap.css"> </head> <body> <a href="bookInfo.jsp">To return to the main page, click</a> <table class="table"> <thead> <tr> <th scope="col">bookId</th> <th scope="col">bookName</th> <th scope="col">bookPrice</th> <th scope="col">operation</th> </tr> </thead> <tbody> <c:forEach items="${booklist}" var="book"> <tr> <th scope="row">${book.bookid}</th> <td>${book.bookname}</td> <td>${book.price}</td> <td> <a href="${pageContext.request.contextPath}/book/toupdateBook">modify</a> <a href="${pageContext.request.contextPath}/book/delBook?bookid=${book.bookid}">delete</a> </td> </tr> </c:forEach> <nav aria-label="Page navigation example"> <ul class="pagination"> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/book/queryByNmme?pageNum=${pageInfo.prePage}" aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <c:forEach items="${pageInfo}" var="p" begin="1" end="${pageInfo.pages}" step="1"> <li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/book/queryByNmme?pageNum=${p}">${p}</a></li> </c:forEach> <li class="page-item"> <a class="page-link" href="${pageContext.request.contextPath}/book/queryByNmme?pageNum=${pageInfo.nextPage}" aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav> </tbody> </table> </body> <script src="${pageContext.request.contextPath}/static/js/bootstrap.js"></script> <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script> </html>
blessing
If you see (slide) here, why don't you give a thumbs up!!! I wish you all a smooth study, a smooth exam, a smooth work, a happy code every day, and a merry Christmas!
Reprint: reprint is welcome, but this statement must be retained without the consent of the author; The original connection must be given in the article; Otherwise, legal liability will be investigated (although no one will read this little broken article)
If a big man sees or finds something wrong, he can write a private letter or comment on it.
It's not easy for Internet workers.