springmvc的理解:https://blog.csdn.net/qq_41879385/article/details/82885516本项目的jsp页面使用bootstrap前端框架:https://blog.csdn.net/qq_41879385/article/details/82431238编译器eclipse,数据库MySQL5.5.25,jdk1.8,tomcat7.0MySQL5.5.25安装教程:https://mp.csdn.net/postedit/82215828在项目中用到的二维码:https://blog.csdn.net/qq_41879385/article/details/81625354

整合项目的时候,整个页面会比较长,所以难免会出现一些不耐烦,没耐心的看,旁边就有我的QQ号啊,直接找我要源码不就行了哈哈。不过我还是建议耐心静下心来看,真的对你帮助很大,要源码的这种方式应该属于初学者。

项目名为:小说书籍网,有问题或者想找我要源码的,都可以到旁边有个我的联系方式。备注CSDN博客。

一、目录结构:

二、数据库

数据库设计,数据脚本下载:https://download.csdn.net/download/qq_41879385/10696480,因为博客已经没有免费下载的功能了,所以C币只选最少的,1个就行。

三、项目开始

在pojo包中创建Novel.java(代表novel表)、Coltype.java(代表coltype),当然,里面的字段、类型跟这两张表是一样的。

但是我还要再加一张表:PageNovel.java,这个是分页的表,呃,实体类的话大家都会,我这里就不在贴出来了。贴出一个分页的类:

PageNovel.java:

package cn.item.pojo;public class PageNovel {private String novelName;private String novelColumn;private Integer page = 1;private Integer start;private Integer size = 10;public String getNovelName() {return novelName;}public void setNovelName(String novelName) {this.novelName = novelName;}public String getNovelColumn() {return novelColumn;}public void setNovelColumn(String novelColumn) {this.novelColumn = novelColumn;}public Integer getPage() {return page;}public void setPage(Integer page) {this.page = page;}public Integer getStart() {return start;}public void setStart(Integer start) {this.start = start;}public Integer getSize() {return size;}public void setSize(Integer size) {this.size = size;}}

在Java Resources下创建一个与src同路径的文件夹config,注意包的名字

在config下创建ApplicationContext-dao.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- 加载配置文件 --><context:property-placeholder location="classpath:db.properties" /><!-- 数据库连接池 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driver}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="maxActive" value="10" /><property name="maxIdle" value="5" /></bean><!-- mapper配置 --><!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 --><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!-- 数据库连接池 --><property name="dataSource" ref="dataSource" /><!-- 加载mybatis的全局配置文件 --><property name="configLocation" value="classpath:SqlMapConfig.xml" /></bean><!-- 配置Mapper扫描器 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="cn.item.dao"/></bean></beans>

ApplicationContext-service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- @Service扫描 --><context:component-scan base-package="cn.item.service"></context:component-scan>
</beans>

ApplicationContext-trans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsdhttp://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"><!-- 事务管理器 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 数据源 --><property name="dataSource" ref="dataSource" /></bean><!-- 通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- 传播行为 --><tx:method name="save*" propagation="REQUIRED" /><tx:method name="insert*" propagation="REQUIRED" /><tx:method name="delete*" propagation="REQUIRED" /><tx:method name="update*" propagation="REQUIRED" /><tx:method name="find*" propagation="SUPPORTS" read-only="true" /><tx:method name="get*" propagation="SUPPORTS" read-only="true" /></tx:attributes></tx:advice><!-- 切面 --><aop:config><aop:advisor advice-ref="txAdvice"pointcut="execution(* cn.item.service.*.*(..))" /></aop:config></beans>

db.properties:

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/你的表名写这?characterEncoding=utf-8
jdbc.username=root
jdbc.password=你的密码写这

log4j.properties:

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# 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

SpringMvc.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsdhttp://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"><!-- 引入字典资源文件 --><context:property-placeholder location="classpath:resource.properties"/><!-- @Controller注解扫描 --><context:component-scan base-package="cn.item.controller"></context:component-scan><!-- 注解驱动:替我们显示的配置了最新版的注解的处理器映射器和处理器适配器 --><mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven><!-- 配置视图解析器 作用:在controller中指定页面路径的时候就不用写页面的完整路径名称了,可以直接写页面去掉扩展名的名称--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 真正的页面路径 =  前缀 + 去掉后缀名的页面名称 + 后缀 --><!-- 前缀 --><property name="prefix" value="/WEB-INF/jsp/"></property><!-- 后缀 --><property name="suffix" value=".jsp"></property></bean><!-- 配置自定义转换器注意: 一定要将自定义的转换器配置到注解驱动上--><bean id="conversionService"class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean></beans>

SqlMapConfig.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration></configuration>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>NovelBook</display-name><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:ApplicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>springMvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:SpringMvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springMvc</servlet-name><url-pattern>*.action</url-pattern></servlet-mapping><filter><filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping>
</web-app>

以上的是配置文件,其实我都是直接复制的,然后在修改一下里面的一些包名。注意包名

业务层:service:

NovelService.java:

package cn.item.service;import java.util.List;import cn.item.pojo.Coltype;
import cn.item.pojo.Novel;
import cn.item.pojo.PageNovel;public interface NovelService {public List<Coltype> findDictByCode(String code);  public List<Novel> findCustomerByVo(PageNovel vo);public Integer findCustomerByVoCount(PageNovel vo);public Novel findNovelById(Long id);public void updateNovelById(Novel novel);public void deleteNovelById(long id);public void insertNovelById(Novel novel);}

NovelServiceImpl.java:

package cn.item.service;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import cn.item.dao.DictMapper;
import cn.item.dao.NovelMapping;
import cn.item.pojo.Coltype;
import cn.item.pojo.Novel;
import cn.item.pojo.PageNovel;@Service
public class NovelServiceImpl implements NovelService{@Autowiredprivate DictMapper dictMapper;@Autowiredprivate NovelMapping novelMapping;@Overridepublic List<Coltype> findDictByCode(String code) {List<Coltype> list = dictMapper.findDictByCode(code);return list;}@Overridepublic List<Novel> findCustomerByVo(PageNovel vo) {List<Novel> list = novelMapping.findCustomerByVo(vo);return list;}@Overridepublic Integer findCustomerByVoCount(PageNovel vo) {Integer count = novelMapping.findCustomerByVoCount(vo);return count;}@Overridepublic Novel findNovelById(Long id) {Novel novel = novelMapping.findNovelById(id);return novel;}@Overridepublic void updateNovelById(Novel novel) {novelMapping.updateNovelById(novel);}@Overridepublic void deleteNovelById(long id) {novelMapping.deleteNovelById(id);}@Overridepublic void insertNovelById(Novel novel) {novelMapping.insertNovelById(novel);}}

数据访问层:dao,也有人用Mapping,都可以:

NovelMapping.java:是小说主表的sql语句的方法,方法名是与service相同的:

package cn.item.dao;import java.util.List;import cn.item.pojo.Novel;
import cn.item.pojo.PageNovel;public interface NovelMapping {public List<Novel> findCustomerByVo(PageNovel vo);public Integer findCustomerByVoCount(PageNovel vo);public Novel findNovelById(Long id);public void updateNovelById(Novel novel);public void deleteNovelById(long id);public void insertNovelById(Novel novel);}

接下就写映射文件:NovelMapping.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="cn.item.dao.NovelMapping"><sql id="novel_where"><where><if test="novelName !=null and novelName !='' ">and a.novel_name LIKE '%${novelName}%'</if><if test="novelColumn !=null and novelColumn !='' ">and a.novel_column=#{novelColumn}</if></where></sql><select id="findCustomerByVo" parameterType="cn.item.pojo.PageNovel" resultType="cn.item.pojo.Novel">SELECT a.`novel_id`,a.`novel_name`,a.`author_name`,a.`author_Introduction`,a.`novel_content`,b.`col_name` novel_columnFROM `novel` aLEFT JOIN `coltype` b ON a.`novel_column` = b.`col_id`<include refid="novel_where"></include>LIMIT #{start},#{size}</select><select id="findCustomerByVoCount" parameterType="cn.item.pojo.PageNovel" resultType="int">SELECT COUNT(*)FROM novel aLEFT JOIN coltype c ON a.novel_column = c.col_id<include refid="novel_where"></include></select><select id="findNovelById" parameterType="long" resultType="cn.item.pojo.Novel">SELECT * FROM novel WHERE novel_id=#{id}</select><update id="updateNovelById" parameterType="cn.item.pojo.Novel">UPDATE novel<set><if test="novel_name !=null and novel_name !='' ">novel_name=#{novel_name},</if><if test="novel_column !=null and novel_column !='' ">novel_column=#{novel_column},</if><if test="author_name !=null and author_name !='' ">author_name=#{author_name},</if><if test="author_Introduction !=null and author_Introduction !='' ">author_Introduction=#{author_Introduction},</if><if test="novel_content !=null and novel_content !='' ">novel_content=#{novel_content},</if></set>WHERE novel_id=#{novel_id}</update><delete id="deleteNovelById" parameterType="long">delete from novel where novel_id =#{id}</delete><insert id="insertNovelById" parameterType="cn.item.pojo.Novel">INSERT INTO `novel`(`novel_name`,`novel_column`,`author_name`,`author_Introduction`,`novel_content`)VALUE(#{novel_name},#{novel_column},#{author_name},#{author_Introduction},#{novel_content});</insert></mapper>

接下就写DictMapper.java,这个类是为了下拉做的:

package cn.item.dao;import java.util.List;import cn.item.pojo.Coltype;public interface DictMapper {public List<Coltype> findDictByCode(String code);}

和DictMapper.java的映射文件:DictMapper.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="cn.item.dao.DictMapper"><select id="findDictByCode" parameterType="string" resultType="cn.item.pojo.Coltype">select * from coltype a WHERE a.col_enable=1 AND a.col_code=#{code} ORDER BY a.col_sort</select>
</mapper>

那么,实体类、数据访问层、业务层都写好了,接下可以写控制层:NovelController.java:

package cn.item.controller;import java.util.List;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;import cn.itcast.utils.Page;
import cn.item.dao.NovelMapping;
import cn.item.pojo.Coltype;
import cn.item.pojo.Novel;
import cn.item.pojo.PageNovel;
import cn.item.service.NovelService;@Controller
@RequestMapping("/novel")
public class NovelController {@Resourceprivate NovelMapping novelMapping;@Autowiredprivate NovelService novelService;@Value("${novel.col.name}")private String column;@RequestMapping("/list")public String list(PageNovel vo,Model model) throws Exception{//小说类型List<Coltype> columnList=novelService.findDictByCode(column);if(vo.getNovelName()!=null){vo.setNovelName(new String(vo.getNovelName().getBytes("iso8859-1"),"utf-8"));}if(vo.getPage()==null){vo.setPage(1);}vo.setStart((vo.getPage() - 1) * vo.getSize());//查询数据库的全部数据List<Novel> resultList = novelService.findCustomerByVo(vo);Integer count = novelService.findCustomerByVoCount(vo);Page<Novel> page= new Page<Novel>();page.setTotal(count);            //总条数page.setSize(vo.getSize());    //每页显示条数page.setPage(vo.getPage());     //总页数page.setRows(resultList);      //分页的数据model.addAttribute("page", page);//下拉菜单model.addAttribute("fromType", columnList);model.addAttribute("novelName", vo.getNovelName());model.addAttribute("novelcolumn", vo.getNovelColumn());return "novel";}@RequestMapping("/detail")@ResponseBodypublic Novel detail(Long id) throws Exception{Novel novel = novelService.findNovelById(id);return novel;}@RequestMapping("/update")public String update(Novel novel) throws Exception{novelService.updateNovelById(novel);return "novel";}@RequestMapping("/delete")public String delete(long id) throws Exception{novelService.deleteNovelById(id);return "novel";}@RequestMapping("/insert")public String insert(Novel novel) throws Exception{novelService.insertNovelById(novel);return "novel";}}

嗯,控制层就这么一个:接下来可以写jsp了。

第一步,在WEB-INF下创建jsp文件夹,里面创建novel.jsp,在SpringMvc.xml中已经配置完整视图解析器了。

在novel.jsp头部创建c标签:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

下面是完整的jsp页面代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%String path = request.getContextPath();String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content=""><title>网站</title><style type="text/css">#qrcode-wrapper{position:absolut;left:80px;top:500px;}
</style><!-- Bootstrap Core CSS -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet"><!-- MetisMenu CSS -->
<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet"><!-- DataTables CSS -->
<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet"><!-- Custom CSS -->
<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet"><!-- Custom Fonts -->
<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"type="text/css">
<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"type="text/css"><!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]><script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script><script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]--></head><body><div id="wrapper"><div id="qrcode-wrapper" beoder="1"><div id="qrcodeCanvas"></div></div><div id="page-wrapper"><div class="row"><div class="col-lg-12"><h1 class="page-wrapper">小说书籍网</h1></div><!-- /.col-lg-12 --></div><!-- /.row --><div class="panel panel-default"><div class="panel-body"><form class="form-inline" action="${pageContext.request.contextPath }/novel/list.action" method="get"><div class="form-group"><label for="novelauthorname">小说名称</label><input type="text" class="form-control" id="novelauthorname" value="${novelName}" name="novelName"></input></div>&nbsp;<div class="form-group"><label for="novelColumnFrom">选择小说类型</label> <select class="form-control" id="novelColumnFrom" name="novelColumn"><option value="">--请选择--</option><c:forEach items="${fromType}" var="item"><option value="${item.col_id}"<c:if test="${item.col_id == novelColumn}"> selected</c:if>>${item.col_name }</option></c:forEach></select></div><button type="submit" class="btn btn-primary">查询</button><div class="btn btn-primary" data-toggle="modal" data-target="#novelInsert" onclick="editNovel(${row.zeng_id})">新增小说</div>           </form></div></div><div class="row"><div class="col-lg-12"><div class="panel panel-default"><div class="panel-heading">小说书籍网</div><!-- /.panel-heading --><table class="table table-bordered table-striped"><thead><tr><th>ID</th><th>小说名称</th><th>所属栏目</th><th>小说作者</th><th>作者简介</th><th>小说摘要</th><th>操作</th></tr><!--  </thead>--><tbody><c:forEach items="${page.rows}" var="row"><tr><td>${row.novel_id}</td><td>${row.novel_name}</td><td>${row.novel_column}</td><td>${row.author_name}</td><td>${row.author_Introduction}</td><td>${row.novel_content}</td><td><a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#novelUpdate" onclick="editNovel(${row.novel_id})">修改</a><a href="#" class="btn btn-danger btn-xs" onclick="deleteNovel(${row.novel_id})">删除</a></td></tr></c:forEach></tbody></table><div class="col-md-12 text-right"><itcast:page url="${pageContext.request.contextPath }/novel/list.action" /></div><!-- /.panel-body --></div><!-- /.panel --></div><!-- /.col-lg-12 --></div></div><!-- /#page-wrapper --></div><!-- 修改小说对话框 --><div class="modal fade" id="novelUpdate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"><div class="modal-dialog" role="document"><div class="modal-content"><!-- 对话框头部信息 --><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title" id="myModalLabel">修改小说图书信息</h4></div><!-- 对话框字段 --><div class="modal-body"><form class="form-horizontal" id="edit_novel_form"><input type="hidden" id="edit_novel_id" name="novel_id"/><div class="form-group"><label for="edit_novel_Name" class="col-sm-2 control-label">小说名称</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_novel_Name" placeholder="小说名称" name="novel_name"></div></div><div class="form-group"><label for="edit_novelColumnFrom" style="float:left;padding:7px 15px 0 27px;">小说类型</label><div class="col-sm-10"><select class="form-control" id="edit_novelColumnFrom" placeholder="小说类型" name="novel_column"><option value="">--请选择--</option><c:forEach items="${fromType}" var="item"><option value="${item.col_id}"<c:if test="${item.col_id == novelColumnFrom}"> selected</c:if>>${item.col_name }</option></c:forEach></select></div></div><div class="form-group"><label for="edit_author_name" class="col-sm-2 control-label">小说作者</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_author_name" placeholder="小说作者" name="author_name"></div></div><div class="form-group"><label for="edit_author_Introduction" class="col-sm-2 control-label">作者简介</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_author_Introduction" placeholder="作者简介" name="author_Introduction"></div></div><div class="form-group"><label for="edit_novel_content" class="col-sm-2 control-label">小说内容</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_novel_content" placeholder="小说内容摘要" name="novel_content"></div></div></form></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button type="button" class="btn btn-primary" onclick="updateNovelById()">确定修改小说书籍信息</button></div></div></div></div><!-- /#wrapper --><!-- 添加小说对话框 --><div class="modal fade" id="novelInsert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"><div class="modal-dialog" role="document"><div class="modal-content"><!-- 对话框头部信息 --><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title" id="myModalLabel">添加小说书籍</h4></div><!-- 对话框字段 --><div class="modal-body"><form class="form-horizontal" id="edit_novel_zeng"><input type="hidden" id="edit_novel_id" name="zeng_id"/><div class="form-group"><label for="edit_novel_Name" class="col-sm-2 control-label">小说名称</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_novel_Name" placeholder="小说名称" name="novel_name"></div></div><div class="form-group"><label for="edit_novelColumnFrom" style="float:left;padding:7px 15px 0 27px;">小说类型</label><div class="col-sm-10"><select class="form-control" id="edit_novelColumnFrom" placeholder="小说类型" name="novel_column"><option value="">--请选择--</option><c:forEach items="${fromType}" var="item"><option value="${item.col_id}"<c:if test="${item.col_id == novelColumnFrom}"> selected</c:if>>${item.col_name }</option></c:forEach></select></div></div><div class="form-group"><label for="edit_author_name" class="col-sm-2 control-label">小说作者</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_author_name" placeholder="小说作者" name="author_name"></div></div><div class="form-group"><label for="edit_author_Introduction" class="col-sm-2 control-label">作者简介</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_author_Introduction" placeholder="作者简介" name="author_Introduction"></div></div><div class="form-group"><label for="edit_novel_content" class="col-sm-2 control-label">小说内容</label><div class="col-sm-10"><input type="text" class="form-control" id="edit_novel_content" placeholder="小说内容摘要" name="novel_content"></div></div></form></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button type="button" class="btn btn-primary" onclick="insertNovelById()">确定添加小说书籍</button></div></div></div></div><!-- /#wrapper --><!-- jQuery --><script src="<%=basePath%>js/jquery.min.js"></script><!-- QRCode --><script src="<%=basePath%>js/jquery-1.11.1.js"></script><script src="<%=basePath%>js/jquery.qrcode.js"></script><script src="<%=basePath%>js/qrcode.js"></script> <script src="<%=basePath%>js/utf.js"></script><!-- Bootstrap Core JavaScript --><script src="<%=basePath%>js/bootstrap.min.js"></script><!-- Metis Menu Plugin JavaScript --><script src="<%=basePath%>js/metisMenu.min.js"></script><!-- DataTables JavaScript --><script src="<%=basePath%>js/jquery.dataTables.min.js"></script><script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script><!-- Custom Theme JavaScript --><script src="<%=basePath%>js/sb-admin-2.js"></script><script type="text/javascript">function editNovel(id) {$.ajax({type:"get",url:"<%=basePath%>novel/detail.action",data:{"id":id},success:function(data) {$("#edit_novel_id").val(data.novel_id);$("#edit_novel_name").val(data.novel_name);$("#edit_novelColumnFrom").val(data.novel_column)$("#edit_author_name").val(data.author_name);$("#edit_author_Introduction").val(data.author_Introduction);$("#edit_novel_content").val(data.novel_content)}});}function updateNovelById() {$.post("<%=basePath%>novel/update.action",$("#edit_novel_form").serialize(),function(data){alert("小说图书书籍更新成功!");window.location.reload();});}function deleteNovel(id) {if(confirm('确实要删除该客户吗?')) {$.post("<%=basePath%>novel/delete.action",{"id":id},function(data){alert("小说删除更新成功!");window.location.reload();});}}function insertNovelById(){$.post("<%=basePath%>novel/insert.action",$("#edit_novel_zeng").serialize(),function(data){alert("新增小说书籍成功");window.location.reload();})}jQuery('#qrcodeCanvas').qrcode({text: "https://blog.csdn.net/qq_41879385",width: "110",               //二维码的宽度height: "110",              //二维码的高度background: "#ffffff",      //二维码的后景色foreground: "#000000",      //二维码的前景色src: "<%=basePath%>image/xingkong.jpg"     //二维码中间的图片});</script>
</body></html>

运行效果:数据可能有点少,因为我之前数据库重装结果一不小心就把整个数据库的文件全部删除了,当时我真的心痛啊,编写了2年是SQL语句一下子全部没了,我叫那个心痛啊,不过还好本人数据库还算牛逼一点嘻嘻,很快有些了一个数据,呃,在我给的数据库脚本中是有添加的SQL语句的,用那些sql语句就可以添加了。

这个页面是有用到bootstrap的,在本文章的头部就有贴出bootstrap的使用教程。

增加效果:利用了bootstrap的模态框效果:

修改也是一样的:但是修改功能有个小细节,在点击修改的时候,在模态框都会显示不同数据的不同数据,什么意思呢,就比如你点8号的修改,在跳出来的模态框就回显示8号的数据信息,而点击7号的修改按钮,就会显示7号的数据信息。

下拉查询:

条件查询:

自此,本项目的整合就到这里了,谢谢点赞,如有问题欢迎评论,我随时都会上博客。

附上源码下载地址:百度网盘。代码有问题及时联系我QQ3506346737,尽快修正。

链接:https://pan.baidu.com/s/1h5iIuyZHL0jCXibahB53jg 
提取码:7kia

使用SSM框架实现增删改查相关推荐

  1. java ssm框架做增删改查,使用SSM框架组合实现增删改查的功能

    基于ssm框架组合的增删改查功能 ssm框架组合之前已经搭建完成了,下面基于该框架组合实现增删改查的功能,首先创建一个数据库和一张表: CREATE DATABASE `ssmteam` /*!401 ...

  2. SSM框架——Mybatis增删改查

    目录 目录 环境配置 增删改查的实现 查询全部 查询单个ID 添加用户 修改用户 删除用户 增删改查-使用注解开发 思路流程:搭建环境-->导入Mybatis--->编写代码---> ...

  3. 【JAVA线上实习】【SSM框架学习】利用SSM框架完成增删改查-----查

    前言 写博客写到脊椎断掉QAQ 知识拓展与延申 -[设计模式] 其实这方面我也不是很懂,有空补充 -[事务] 以上关于事务的所有解释来自于博客: https://blog.csdn.net/CSDN_ ...

  4. SSM框架的增删改查之用户登录

    mapper层 /*** 根据用户名和密码查询*/@Select("select * " +"from user " +"where username ...

  5. EF框架实现增删改查

           EF框架实现增删改查 1.创建数据库:先创建两张表,文章类型表以及文章详情表,设置主外键(ID,Catelogid) Catelog:文章类型表 字段:Id(自增),Name,[Cont ...

  6. ssm整合的增删改查

    maven+ssm+bootstrap实现简单的增删改查 学习完ssm框架以后 做的第一个完整的增删改查 是在博客园找到的一个小demo,我自己稍微修改了一下,加入了bootstrap和mybatis ...

  7. flask框架数据库增删改查

    from flask import Flask import os from flask_sqlalchemy import SQLAlchemy import pymysql app=Flask(_ ...

  8. medoo php 教程,使用Medoo框架完成增删改查功能

    摘要:配置Medoo框架: // 配置Medoo框架 // 这是最简单的方法,下载medoo源文件,放到你的PHP开发目录里,载入即可 require 'Medoo/medoo.php'; use M ...

  9. 使用Mybatis框架完成增删改查操作

    一,MyBatis简介 MyBatis是一一个开源.轻量级的数据持久化框架,是JDBC和Hibernate的替代方案. MyBatis 前身为IBatis, 2002 年由Clinton Begin发 ...

最新文章

  1. 【转】XCode: duplicate symbol 解决方案
  2. Hibernate组件(Component)映射
  3. 解决redhat的未注册问题
  4. 窗口分析函数_2_生成同值重复排名序号
  5. 简洁!get请求和post请求的区别——Web网络系列学习笔记
  6. oracle数据库开多线程,学习笔记:Oracle表数据导入 DBA常用单线程插入 多线程插入 sql loader三种表数据导入案例...
  7. 有了代码怎么用python爬虫_python实现简单爬虫功能
  8. 《Linux内核原理与设计》第十一周作业 ShellShock攻击实验
  9. node解决通过npm无法安装forever的方法
  10. Python机器学习工具箱
  11. Mysql binlog 的写入机制
  12. sonarqube插件开发(二) 开发插件
  13. 微信小程序表格前后台分页
  14. 数值计算(二)之插值法与线性回归(拉格朗日插值法,牛顿插值法,赫米特插值法,最小二乘法)
  15. 实验7-3-8 输出大写英文字母
  16. 什么是GSM,CDMA和3G?
  17. Matlab中mod函数使用
  18. ACM如何入门,ACM竞赛需要学习哪些算法?
  19. layUI基本使用2(js)
  20. MySQL 数据库之 MMM 高可用架构构建

热门文章

  1. 魅族android n彩蛋,魅族Flyme Android 10终于发放:强制开启90Hz彩蛋
  2. VS中,0x00007FF7ABF6A8CE 处有未经处理的异常(在 TIF_YUV_vs.exe 中): 0xC0000094: Integer division by zero
  3. 一个想法从构思到实现只需7天
  4. python初始画笔_Python基本画笔标题-1,基础,刷,题录
  5. Android蓝牙连接之SPP协议
  6. android要比ios耗电,这几个原因导致苹果手机耗电比安卓手机快
  7. 【愚公系列】2023年06月 Bugku-Web(bp)
  8. Android ANR 搜集
  9. 信标组的比赛路径设计
  10. 夸克真的实用吗,其实除了它还有更好用的浏览器