整合SSM框架 – 第一个SSM项目
学完MyBatis、Spring、SpringMVC,做一个基于SSM框架的基础项目–书籍管理系统,要求可以实现数据的增删改查,业务运行逻辑明了,分层开发,用来巩固学习
目标:
- 配置SSM框架
- 实现基础的增删改查功能
- 具备后续方便的拓展功能
- 界面设计整洁
最终效果:
-
全部书籍页面
-
新增书籍页面
-
查询书籍页面
环境:
开发环境
环境:
- IDEA 2021.2.1
- MySQL 8
- Tomcat 9
- Maven 3.8
数据库环境
创建一个存放书籍数据的数据库表
数据库ssmbuild 书籍信息表books 主键bookID自动增长 所有字段都不能为空
CREATE
DATABASE `ssmbuild`;
USE
`ssmbuild`;
-- 创建图书表
CREATE TABLE `books`
(
`bookID` INT(10) NOT NULL AUTO_INCREMENT COMMENT '图书ID',
`bookName` VARCHAR(100) NOT NULL COMMENT '书名',
`bookCounts` INT(11) NOT NULL COMMENT '数量',
`detail` VARCHAR(200) NOT NULL COMMENT '描述',
KEY `bookID` (`bookID`)
) ENGINE = INNODB
DEFAULT CHARSET = utf8;
-- 插入数据
INSERT INTO `books`(`bookID`, `bookName`, `bookCounts`, `detail`)
VALUES (1, 'JAVA', 34, '从入门到放弃'),
(2, 'MySQL', 23, '从删库到跑路'),
(3, 'Linux', 33, '从进门到进牢')
基本环境搭建
项目结构
项目搭建
-
新建一个Maven项目 ssmbuild , 添加JavaWeb框架的支持
-
在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>
-
配置项目依赖
-
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>
-
建立基本结构和配置框架
-
编写java代码
-
编写数据库对应的实体类 pojo.Books.java (注:这里使用了Lombok插件)
@Data @AllArgsConstructor @NoArgsConstructor public class Books { private int bookID; private String bookName; private int bookCounts; private String detail; }
-
编写Mapper接口 mapper/BookMapper.java
public interface BookMapper { // 增加 int insertBook(Books books); // 删除 int deleteBook(@Param("bookId") int id); // 修改 int updateBook(Books books); // ID查询 Books queryBookById(int id); // 查询全部 List<Books> queryAllBook(); // 模糊查询 List<Books> queryBookName(@Param("bookName") String bookName); }
-
编写Mapper接口对应的XML文件
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.codeonce.mapper.BookMapper"> <!--增加--> <insert id="insertBook" parameterType="Books"> INSERT INTO ssmbuild.books(bookName, bookCounts, detail) VALUES (#{bookName}, #{bookCounts}, #{detail}); </insert> <!--删除--> <delete id="deleteBook" parameterType="int"> DELETE FROM ssmbuild.books WHERE bookID = #{bookId}; </delete> <!--修改--> <update id="updateBook" parameterType="Books"> UPDATE ssmbuild.books SET bookName=#{bookName}, bookCounts=#{bookCounts}, detail=#{detail} WHERE bookID = #{bookID}; </update> <!--根据ID查询--> <select id="queryBookById" resultType="Books"> SELECT * FROM ssmbuild.books WHERE bookID = #{bookId}; </select> <!--查询全部--> <select id="queryAllBook" resultType="Books"> SELECT * FROM ssmbuild.books; </select> <!--模糊查询--> <select id="queryBookName" resultType="Books"> SELECT * FROM ssmbuild.books WHERE bookName LIKE CONCAT('%', #{bookName}, '%'); </select> </mapper>
-
编写Service层接口 service/BookService.java
public interface BookService { // 增加 int insertBook(Books books); // 删除 int deleteBook(@Param("bookId") int id); // 修改 int updateBook(Books books); // ID查询 Books queryBookById(int id); // 查询全部 List<Books> queryAllBook(); // 查询全部 List<Books> queryBookName(String bookName); }
-
编写Service层接口实现类 service/BookServiceImpl.java
public class BookServiceImpl implements BookService { // 配置LOG4J private static final Logger logger = Logger.getLogger(BookServiceImpl.class); // service调用mapper层 private BookMapper bookMapper; public void setBookMapper(BookMapper bookMapper) { this.bookMapper = bookMapper; } @Override public int insertBook(Books books) { return bookMapper.insertBook(books); } @Override public int deleteBook(int id) { return bookMapper.deleteBook(id); } @Override public int updateBook(Books books) { return bookMapper.updateBook(books); } @Override public Books queryBookById(int id) { return bookMapper.queryBookById(id); } @Override public List<Books> queryAllBook() { return bookMapper.queryAllBook(); } @Override public List<Books> queryBookName(String bookName) { return bookMapper.queryBookName(bookName); } }
-
编写控制层 controller/BookController.java
import com.codeonce.pojo.Books; import com.codeonce.service.BookService; 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.PathVariable; 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 queryAll(Model model) { List<Books> booksList = bookService.queryAllBook(); model.addAttribute("booksList", booksList); return "allBook"; } // 跳转到增加书籍页面 @RequestMapping("/toAddBook") public String toAddBookPaper() { return "addBook"; } // 添加书籍的请求 @RequestMapping("/addBook") public String insertBook(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}") public String toUpdateBookPaper(@PathVariable("bookID") int id, Model model) { Books books = bookService.queryBookById(id); model.addAttribute("books", books); return "updateBook"; } // 修改书籍请求 @RequestMapping("/updateBook") public String updateBook(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}") public String deleteBook(@PathVariable("bookID") int id) { int result = bookService.deleteBook(id); if (result > 0) { System.out.println("删除数据成功" + id); } return "redirect:/book/allBook"; } // 查询书籍 @RequestMapping("/queryBook") public String queryBook(String bookName, Model model) { // bookName = "%" + bookName + "%"; List<Books> booksList = bookService.queryBookName(bookName); System.err.println("queryBook" + booksList); model.addAttribute("booksList", booksList); return "allBook"; } }
-
-
配置文件
-
数据库参数配置文件 resources/database.properties
jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai jdbc.username=root jdbc.password=admin
-
LOG4J日志配置文件 resources/log4j.properties
# 将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码 log4j.rootLogger=DEBUG,console,file # 控制台输出的相关设置 log4j.appender.console=org.apache.log4j.ConsoleAppender log4j.appender.console.Target=System.out log4j.appender.console.Threshold=DEBUG log4j.appender.console.layout=org.apache.log4j.PatternLayout log4j.appender.console.layout.ConversionPattern=[%c]-%m%n log4j.appender.Console.encoding=UTF-8 # 文件输出的相关设置 log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=./log/com.mydemo.log log4j.appender.file.MaxFileSize=10mb log4j.appender.file.Threshold=DEBUG log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=[%p][%d{yyyy-MM-dd}][%c]%m%n log4j.appender.file.encoding=UTF-8 # 日志输出级别 log4j.logger.org.mybatis=DEBUG log4j.logger.java.sql=DEBUG log4j.logger.java.sql.Statement=DEBUG log4j.logger.java.sql.ResultSet=DEBUG log4j.logger.java.sql.PreparedStatement=DEBUG
-
写dao层操作配置文件 resources/spring-dao.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns: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-placeholder location="classpath:database.properties"/> <!--2.连接池 dbcp: 半自动化操作,不能自动连接 c3p0: 自动化操作,自动化的加载配置文件,并且可以自动设置到对象中 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- 配置连接池属性 --> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- c3p0连接池的私有属性 --> <property name="maxPoolSize" value="30"/> <property name="minPoolSize" value="10"/> <!-- 关闭连接后不自动commit --> <property name="autoCommitOnClose" value="false"/> <!-- 获取连接超时时间 --> <property name="checkoutTimeout" value="10000"/> <!-- 当获取连接失败重试次数 --> <property name="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--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!--绑定MyBatis配置文件--> <property name="configLocation" value="classpath:mybatis-config.xml"/> </bean> <!--配置Mapper接口扫描包,动态的实现了Mapper接口可以注入的Spring容器中--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!--注入sqlSessionFactory--> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/> <!--要扫描的Mapper包--> <property name="basePackage" value="com.codeonce.mapper"/> </bean> </beans>
-
写service层操作配置文件 resources/spring-service.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: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-scan base-package="com.codeonce.service"/> <!--2.将我们所有的业务类注入到Spring,可以通过配置或注解实现--> <bean id="BookServiceImpl" class="com.codeonce.service.BookServiceImpl"> <property name="bookMapper" ref="bookMapper"/> </bean> <!--3.声明式事务配置--> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!--注入数据源--> <property name="dataSource" ref="dataSource"/> </bean> <!--4.AOP事务支持--> <!--结合AOP实现事务的织入--> <!--配置事务通知--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <!--给那些方法配置事务--> <!--配置事务的传播特性:new propagation--> <tx:attributes> <tx:method name="*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!--配置事务切入--> <aop:config> <!--定义切入点--> <aop:pointcut id="txPointCut" expression="execution(* com.codeonce.mapper.*.*(..))"/> <!--配置切入位置--> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/> </aop:config> </beans>
-
写MVC操作配置文件 resources/spring-mvc.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: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-scan base-package="com.codeonce.controller"/> <!--4.视图解析器--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver"> <!--前缀--> <property name="prefix" value="/WEB-INF/jsp/"/> <!--后缀--> <property name="suffix" value=".jsp"/> </bean> </beans>
-
mybatis框架配置 resources/mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.ory//DTD Config 3.0//EN" "htpp://mybatis.org/dtd/mybatis-3-config.dtd"> <!--mybatis的主配置文件--> <configuration> <!--设置--> <settings> <!--LOG4j日志工厂实现--> <setting name="logImpl" value="STDOUT_LOGGING"/> <!--<setting name="logImpl" value="LOG4J"/>--> </settings> <!--别名--> <typeAliases> <typeAlias type="com.codeonce.pojo.Books" alias="Books"/> </typeAliases> <mappers> <mapper class="com.codeonce.mapper.BookMapper"/> </mappers> </configuration>
-
导入所有配置文件 resources/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns: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/> <import resource="classpath:spring-dao.xml"/> <import resource="classpath:spring-service.xml"/> <import resource="classpath:spring-mvc.xml"/> </beans>
-
在web.xml 中绑定配置 web/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="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>
-
-
JSP页面
-
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"> 全部书籍 </a> <a class="btn btn-primary" href="${pageContext.request.contextPath}/book/toAddBook"> 新增书籍 </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"> 查询 </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文章来源:https://www.toymoban.com/news/detail-478583.html
<%@ 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 (此处可以使用新增书籍页面复用)文章来源地址https://www.toymoban.com/news/detail-478583.html
<%@ 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>
总结
- 代码还有很多地方可以改进 比如页面代码复用 方法复用 动态SQL
- 后续进行项目拓展都可以基于需求进行增加mapper接口
到了这里,关于整合SSM框架 -- 简单基础SSM项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!