0


整合SSM框架 -- 简单基础SSM项目

整合SSM框架 – 第一个SSM项目

学完MyBatis、Spring、SpringMVC,做一个基于SSM框架的基础项目–书籍管理系统,要求可以实现数据的增删改查,业务运行逻辑明了,分层开发,用来巩固学习

目标:

  • 配置SSM框架
  • 实现基础的增删改查功能
  • 具备后续方便的拓展功能
  • 界面设计整洁

最终效果:

  • 全部书籍页面image-20211101085818341
  • 新增书籍页面image-20211101085908180
  • 查询书籍页面image-20211101085956543

环境:

开发环境

环境:

  • IDEA 2021.2.1
  • MySQL 8
  • Tomcat 9
  • Maven 3.8

数据库环境

创建一个存放书籍数据的数据库表

数据库ssmbuild 书籍信息表books 主键bookID自动增长 所有字段都不能为空

CREATEDATABASE`ssmbuild`;USE`ssmbuild`;-- 创建图书表CREATETABLE`books`(`bookID`INT(10)NOTNULLAUTO_INCREMENTCOMMENT'图书ID',`bookName`VARCHAR(100)NOTNULLCOMMENT'书名',`bookCounts`INT(11)NOTNULLCOMMENT'数量',`detail`VARCHAR(200)NOTNULLCOMMENT'描述',KEY`bookID`(`bookID`))ENGINE=INNODBDEFAULTCHARSET= utf8;-- 插入数据INSERTINTO`books`(`bookID`,`bookName`,`bookCounts`,`detail`)VALUES(1,'JAVA',34,'从入门到放弃'),(2,'MySQL',23,'从删库到跑路'),(3,'Linux',33,'从进门到进牢')

基本环境搭建

项目结构

image-20211101090503331

image-20211101090603813

项目搭建

  1. 新建一个Maven项目 ssmbuild , 添加JavaWeb框架的支持
  2. 在pom文件中导入所需依赖<dependencies><!--junit--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version></dependency><!--数据库驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><!--数据库连接池: c3p0--><dependency><groupId>com.mchange</groupId><artifactId>c3p0</artifactId><version>0.9.5.5</version></dependency><!--Servlet / JSP--><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!--MyBatis--><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.7</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.6</version></dependency><!--Spring--><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.11</version></dependency><!--spring操作数据库,还需要spring-jdbc--><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.3.11</version></dependency><!--AOP切入包--><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.7</version></dependency><!--lombok--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.22</version></dependency><!--log4j--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies>image-20211101091934609
  3. 配置项目依赖image-20211101092221726image-20211101092320031
  4. Maven资源过滤设置<!--在build中配置resources 来防止资源导出失败的问题--><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>
  5. 建立基本结构和配置框架image-20211101092656456
  6. 编写java代码- 编写数据库对应的实体类 pojo.Books.java (注:这里使用了Lombok插件)@Data@AllArgsConstructor@NoArgsConstructorpublicclassBooks{privateint bookID;privateString bookName;privateint bookCounts;privateString detail;}- 编写Mapper接口 mapper/BookMapper.javapublicinterfaceBookMapper{// 增加intinsertBook(Books books);// 删除intdeleteBook(@Param("bookId")int id);// 修改intupdateBook(Books books);// ID查询BooksqueryBookById(int id);// 查询全部List<Books>queryAllBook();// 模糊查询List<Books>queryBookName(@Param("bookName")String bookName);}- 编写Mapper接口对应的XML文件<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEmapperPUBLIC"-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mappernamespace="com.codeonce.mapper.BookMapper"><!--增加--><insertid="insertBook"parameterType="Books"> INSERT INTO ssmbuild.books(bookName, bookCounts, detail) VALUES (#{bookName}, #{bookCounts}, #{detail}); </insert><!--删除--><deleteid="deleteBook"parameterType="int"> DELETE FROM ssmbuild.books WHERE bookID = #{bookId}; </delete><!--修改--><updateid="updateBook"parameterType="Books"> UPDATE ssmbuild.books SET bookName=#{bookName}, bookCounts=#{bookCounts}, detail=#{detail} WHERE bookID = #{bookID}; </update><!--根据ID查询--><selectid="queryBookById"resultType="Books"> SELECT * FROM ssmbuild.books WHERE bookID = #{bookId}; </select><!--查询全部--><selectid="queryAllBook"resultType="Books"> SELECT * FROM ssmbuild.books; </select><!--模糊查询--><selectid="queryBookName"resultType="Books"> SELECT * FROM ssmbuild.books WHERE bookName LIKE CONCAT('%', #{bookName}, '%'); </select></mapper>- 编写Service层接口 service/BookService.javapublicinterfaceBookService{// 增加intinsertBook(Books books);// 删除intdeleteBook(@Param("bookId")int id);// 修改intupdateBook(Books books);// ID查询BooksqueryBookById(int id);// 查询全部List<Books>queryAllBook();// 查询全部List<Books>queryBookName(String bookName);}- 编写Service层接口实现类 service/BookServiceImpl.javapublicclassBookServiceImplimplementsBookService{// 配置LOG4JprivatestaticfinalLogger logger =Logger.getLogger(BookServiceImpl.class);// service调用mapper层privateBookMapper bookMapper;publicvoidsetBookMapper(BookMapper bookMapper){this.bookMapper = bookMapper;}@OverridepublicintinsertBook(Books books){return bookMapper.insertBook(books);}@OverridepublicintdeleteBook(int id){return bookMapper.deleteBook(id);}@OverridepublicintupdateBook(Books books){return bookMapper.updateBook(books);}@OverridepublicBooksqueryBookById(int id){return bookMapper.queryBookById(id);}@OverridepublicList<Books>queryAllBook(){return bookMapper.queryAllBook();}@OverridepublicList<Books>queryBookName(String bookName){return bookMapper.queryBookName(bookName);}}- 编写控制层 controller/BookController.javaimportcom.codeonce.pojo.Books;importcom.codeonce.service.BookService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.beans.factory.annotation.Qualifier;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importjava.util.List;@Controller@RequestMapping("/book")publicclassBookController{// controller 调用 service层@Autowired@Qualifier("BookServiceImpl")privateBookService bookService;// 查询全部的书籍,并且返回到一书籍展示的页面@RequestMapping("/allBook")publicStringqueryAll(Model model){List<Books> booksList = bookService.queryAllBook(); model.addAttribute("booksList", booksList);return"allBook";}// 跳转到增加书籍页面@RequestMapping("/toAddBook")publicStringtoAddBookPaper(){return"addBook";}// 添加书籍的请求@RequestMapping("/addBook")publicStringinsertBook(Books books){System.out.println("addBook=>"+ books);int result = bookService.insertBook(books);if(result >0){System.out.println("添加数据成功"+ books);}return"redirect:/book/allBook";}// 跳转到修改书籍页面@RequestMapping("/toUpdateBook/{bookID}")publicStringtoUpdateBookPaper(@PathVariable("bookID")int id,Model model){Books books = bookService.queryBookById(id); model.addAttribute("books", books);return"updateBook";}// 修改书籍请求@RequestMapping("/updateBook")publicStringupdateBook(Books books){System.out.println("updateBook=>"+ books);int result = bookService.updateBook(books);if(result >0){System.out.println("修改数据成功"+ books);}return"redirect:/book/allBook";}// 删除书籍请求@RequestMapping("/deleteBook/{bookID}")publicStringdeleteBook(@PathVariable("bookID")int id){int result = bookService.deleteBook(id);if(result >0){System.out.println("删除数据成功"+ id);}return"redirect:/book/allBook";}// 查询书籍@RequestMapping("/queryBook")publicStringqueryBook(String bookName,Model model){// bookName = "%" + bookName + "%";List<Books> booksList = bookService.queryBookName(bookName);System.err.println("queryBook"+ booksList); model.addAttribute("booksList", booksList);return"allBook";}}
  7. 配置文件- 数据库参数配置文件 resources/database.propertiesjdbc.driver=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghaijdbc.username=rootjdbc.password=admin- LOG4J日志配置文件 resources/log4j.properties# 将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码log4j.rootLogger=DEBUG,console,file# 控制台输出的相关设置log4j.appender.console=org.apache.log4j.ConsoleAppenderlog4j.appender.console.Target=System.outlog4j.appender.console.Threshold=DEBUGlog4j.appender.console.layout=org.apache.log4j.PatternLayoutlog4j.appender.console.layout.ConversionPattern=[%c]-%m%nlog4j.appender.Console.encoding=UTF-8# 文件输出的相关设置log4j.appender.file=org.apache.log4j.RollingFileAppenderlog4j.appender.file.File=./log/com.mydemo.loglog4j.appender.file.MaxFileSize=10mblog4j.appender.file.Threshold=DEBUGlog4j.appender.file.layout=org.apache.log4j.PatternLayoutlog4j.appender.file.layout.ConversionPattern=[%p][%d{yyyy-MM-dd}][%c]%m%nlog4j.appender.file.encoding=UTF-8# 日志输出级别log4j.logger.org.mybatis=DEBUGlog4j.logger.java.sql=DEBUGlog4j.logger.java.sql.Statement=DEBUGlog4j.logger.java.sql.ResultSet=DEBUGlog4j.logger.java.sql.PreparedStatement=DEBUG- 写dao层操作配置文件 resources/spring-dao.xml<?xml version="1.0" encoding="UTF-8"?><beansxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!--1.关联数据库配置文件--><context:property-placeholderlocation="classpath:database.properties"/><!--2.连接池 dbcp: 半自动化操作,不能自动连接 c3p0: 自动化操作,自动化的加载配置文件,并且可以自动设置到对象中 --><beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"><!-- 配置连接池属性 --><propertyname="driverClass"value="${jdbc.driver}"/><propertyname="jdbcUrl"value="${jdbc.url}"/><propertyname="user"value="${jdbc.username}"/><propertyname="password"value="${jdbc.password}"/><!-- c3p0连接池的私有属性 --><propertyname="maxPoolSize"value="30"/><propertyname="minPoolSize"value="10"/><!-- 关闭连接后不自动commit --><propertyname="autoCommitOnClose"value="false"/><!-- 获取连接超时时间 --><propertyname="checkoutTimeout"value="10000"/><!-- 当获取连接失败重试次数 --><propertyname="acquireRetryAttempts"value="2"/></bean><!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean>--><!--3.SqlSessionFactory--><beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><!--绑定MyBatis配置文件--><propertyname="configLocation"value="classpath:mybatis-config.xml"/></bean><!--配置Mapper接口扫描包,动态的实现了Mapper接口可以注入的Spring容器中--><beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer"><!--注入sqlSessionFactory--><propertyname="sqlSessionFactoryBeanName"value="sqlSessionFactory"/><!--要扫描的Mapper包--><propertyname="basePackage"value="com.codeonce.mapper"/></bean></beans>- 写service层操作配置文件 resources/spring-service.xml<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><!--1.扫描service下的包--><context:component-scanbase-package="com.codeonce.service"/><!--2.将我们所有的业务类注入到Spring,可以通过配置或注解实现--><beanid="BookServiceImpl"class="com.codeonce.service.BookServiceImpl"><propertyname="bookMapper"ref="bookMapper"/></bean><!--3.声明式事务配置--><beanid="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!--注入数据源--><propertyname="dataSource"ref="dataSource"/></bean><!--4.AOP事务支持--><!--结合AOP实现事务的织入--><!--配置事务通知--><tx:adviceid="txAdvice"transaction-manager="transactionManager"><!--给那些方法配置事务--><!--配置事务的传播特性:new propagation--><tx:attributes><tx:methodname="*"propagation="REQUIRED"/></tx:attributes></tx:advice><!--配置事务切入--><aop:config><!--定义切入点--><aop:pointcutid="txPointCut"expression="execution(* com.codeonce.mapper.*.*(..))"/><!--配置切入位置--><aop:advisoradvice-ref="txAdvice"pointcut-ref="txPointCut"/></aop:config></beans>- 写MVC操作配置文件 resources/spring-mvc.xml<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--1.解锁驱动--><mvc:annotation-driven/><!--2.静态资源过滤--><mvc:default-servlet-handler/><!--3.扫描包: controller--><context:component-scanbase-package="com.codeonce.controller"/><!--4.视图解析器--><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"id="viewResolver"><!--前缀--><propertyname="prefix"value="/WEB-INF/jsp/"/><!--后缀--><propertyname="suffix"value=".jsp"/></bean></beans>- mybatis框架配置 resources/mybatis-config.xml<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPEconfigurationPUBLIC"-//mybatis.ory//DTD Config 3.0//EN""htpp://mybatis.org/dtd/mybatis-3-config.dtd"><!--mybatis的主配置文件--><configuration><!--设置--><settings><!--LOG4j日志工厂实现--><settingname="logImpl"value="STDOUT_LOGGING"/><!--<setting name="logImpl" value="LOG4J"/>--></settings><!--别名--><typeAliases><typeAliastype="com.codeonce.pojo.Books"alias="Books"/></typeAliases><mappers><mapperclass="com.codeonce.mapper.BookMapper"/></mappers></configuration>- 导入所有配置文件 resources/applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><beansxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns="http://www.springframework.org/schema/beans"xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--开启注解的支持--><context:annotation-config/><importresource="classpath:spring-dao.xml"/><importresource="classpath:spring-service.xml"/><importresource="classpath:spring-mvc.xml"/></beans>- 在web.xml 中绑定配置 web/WEB-INF/web.xml<?xml version="1.0" encoding="UTF-8"?><web-appxmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--配置DispatchServlet:这个是SpringMVC的核心:请求分发器、前端控制器--><servlet><servlet-name>DispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--DispatchServlet要绑定SpringMVC的配置文件--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></init-param><!--启动级别 数字越小启动越快--><load-on-startup>1</load-on-startup></servlet><!-- 在SpringMVC中/和/*的区别 /: 只匹配所有的请求,不会去匹配JSP页面 /*: 只匹配所有的请求,包括JSP页面 --><servlet-mapping><servlet-name>DispatcherServlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!--配置SpringMVC的乱码过滤器--><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--Session--><session-config><session-timeout>15</session-timeout></session-config></web-app>
  8. JSP页面- image-20211101095203328- index.jsp 跳转页面 web/index.jsp<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %><html><head> <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: deepskyblue; border-radius: 4px; } </style></head><body><h3> <a href="${pageContext.request.contextPath}/book/allBook">点击进入列表页</a></h3></body></html>- 书籍列表JSP web/WEB-INF/jsp/allBook.jsp (集成查询所有和模糊查询)<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ page contentType="text/html;charset=UTF-8" language="java" %><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>书籍列表</title> <!-- 引入 Bootstrap --> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css"></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"> <%--新增--%> <div class="col-md-4 column"> <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/allBook">&nbsp;全部书籍&nbsp;</a> <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddBook">&nbsp;新增书籍&nbsp;</a> </div> <div class="col-md-4"></div> <%--查询--%> <div class="col-md-4 column" style="text-align: right"> <form action="${pageContext.request.contextPath}/book/queryBook" method="post" class="form-inline"> <div class="form-group"><%-- <span style="color: red">未查询到任何结果</span>--%> <label> <input type="text" class="form-control" name="bookName" placeholder="请输入要查询的书籍名称"> </label> </div> <button type="submit" class="btn btn-primary" style="vertical-align: top">&nbsp;查询&nbsp;</button> </form> </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> <th>操作</th> </tr> </thead> <tbody> <c:forEach var="book" items="${booksList}"> <tr> <td>${book.bookID}</td> <td>${book.bookName}</td> <td>${book.bookCounts}</td> <td>${book.detail}</td> <td> <a href="${pageContext.request.contextPath}/book/toUpdateBook/${book.bookID}">更改</a> | <a href="${pageContext.request.contextPath}/book/deleteBook/${book.bookID}">删除</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div></div>- 新增书籍页面 web/WEB-INF/jsp/addBook.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> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css"></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> <form action="${pageContext.request.contextPath}/book/addBook" method="post"> <div class="form-group"> <label for="bookName">书籍名称:</label> <input type="text" class="form-control" id="bookName" name="bookName" required> </div> <div class="form-group"> <label for="bookCounts">书籍数量:</label> <input type="text" class="form-control" id="bookCounts" name="bookCounts" required> </div> <div class="form-group"> <label for="detail">书籍描述:</label> <input type="text" class="form-control" id="detail" name="detail" required> </div> <div class="form-group"> <input type="submit" class="form-control btn-primary" value="添加"> </div> </form></div></body></html>- 更新书籍JSP页面 web/WEB-INF/jsp/updateBook.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> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link rel="stylesheet" href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css"></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> <form action="${pageContext.request.contextPath}/book/updateBook" method="post"> <div class="form-group"> <label for="bookName">书籍名称:</label> <input type="text" class="form-control" id="bookName" name="bookName" required value="${books.bookName}"> </div> <div class="form-group"> <label for="bookCounts">书籍数量:</label> <input type="text" class="form-control" id="bookCounts" name="bookCounts" required value="${books.bookCounts}"> </div> <div class="form-group"> <label for="detail">书籍描述:</label> <input type="text" class="form-control" id="detail" name="detail" required value="${books.detail}"> </div> <div class="form-group"> <input type="hidden" value="${books.bookID}" name="bookID"> <input type="submit" class="form-control btn-primary" value="修改"> </div> </form></div></body></html>## 总结1. 代码还有很多地方可以改进 比如页面代码复用 方法复用 动态SQL2. 后续进行项目拓展都可以基于需求进行增加mapper接口
标签: java ssm spring

本文转载自: https://blog.csdn.net/qq_46263740/article/details/121074848
版权归原作者 温柔且无情 所有, 如有侵权,请联系我们删除。

“整合SSM框架 -- 简单基础SSM项目”的评论:

还没有评论