浅谈IDEA+Maven 整合SSM框架实现简单的增删改查
2019-06-27 20:05
302 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Mascare_whut/article/details/93904529
SSM
SSM(Spring+SpringMVC+MyBatis)框架集由Spring、MyBatis两个开源框架整合而成(SpringMVC是Spring中的部分内容)。常作为数据源较简单的web项目的框架。
Spring
Spring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象。也可以称之为项目中的粘合剂。
Spring的核心思想是IoC(控制反转),即不再需要程序员去显式地`new`一个对象,而是让Spring框架帮你来完成这一切。
SpringMVC
SpringMVC在项目中拦截用户请求,它的核心Servlet即DispatcherServlet承担中介或是前台这样的职责,将用户请求通过HandlerMapping去匹配Controller,Controller就是具体对应请求所执行的操作。SpringMVC相当于SSH框架中struts。
mybatis
mybatis是对jdbc的封装,它让数据库底层操作变的透明。mybatis的操作都是围绕一个sqlSessionFactory实例展开的。mybatis通过配置文件关联到各实体类的Mapper文件,Mapper文件中配置了每个类对数据库所需进行的sql语句映射。在每次与数据库交互时,通过sqlSessionFactory拿到一个sqlSession,再执行sql命令。
框架构造最终结果
依照上图建立相应的xml文件,jsp文件,类和接口等,然后对pom.xml进行初始配置
[code]<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>SSMtest</groupId> <artifactId>SSMtest</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>first Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring.version>5.0.3.RELEASE</spring.version> <mybatis.version>3.4.4</mybatis.version> </properties> <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- 第一部分:Spring 配置--> <!-- Spring core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <!-- Spring DAO --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <!-- Spring mvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <!-- 第二部分:Servlet web --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.4</version> </dependency> <!-- 第三部分:数据库和mybatis --> <!-- 数据库 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency> <!-- 数据库连接池 --> <dependency> <groupId>co 3ff7 m.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <!-- mybatis-spring整合包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.1</version> </dependency> <!-- 第四部分:日志 --> <!-- 实现slf4j接口并整合 --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.1</version> </dependency> </dependencies> <build> <finalName>first</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
将其他文件配置好后,开始编写jsp文件,将页面展现出来
index
[code]<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <% pageContext.setAttribute("path", request.getContextPath()); %> <!DOCTYPE HTML> <html> <head> <title>首页</title> <style type="text/css"> 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> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基于SSM框架的管理系统:简单实现增、删、改、查。 </h1> </div> </div> </div> </div> <br><br> <h3> <a href="${path }/paper/allPaper">点击进入管理页面</a> </h3> </body> </html>
addPaper
[code]<%-- Created by IntelliJ IDEA. User: lenovo Date: 2018/4/7 Time: 16:45 To change this template use File | Settings | File Templates. --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <html> <head> <title>新增论文</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基于SSM框架的管理系统:简单实现增、删、改、查。 </h1> </div> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> <small>新增论文</small> </h1> </div> </div> </div> <form action="" name="userForm"> 论文名称:<input type="text" name="paperName"><br><br><br> 论文数量:<input type="text" name="paperNum"><br><br><br> 论文详情:<input type="text" name="paperDetail"><br><br><br> <input type="button" value="添加" οnclick="addPaper()"> </form> <script type="text/javascript"> function addPaper() { var form = document.forms[0]; form.action = "<%=basePath %>paper/addPaper"; form.method = "post"; form.submit(); } </script> </div>
allPaper
[code]<%-- Created by IntelliJ IDEA. User: lenovo Date: 2018/4/6 Time: 16:57 To change this template use File | Settings | File Templates. --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String appPath = request.getContextPath(); %> <html> <head> <title>Paper列表</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基于SSM框架的管理系统:简单实现增、删、改、查。 </h1> </div> </div> </div> <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="${path}/paper/toAddPaper">新增</a> </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="paper" items="${requestScope.get('list')}" varStatus="status"> <tr> <td>${paper.paperId}</td> <td>${paper.paperName}</td> <td>${paper.paperNum}</td> <td>${paper.paperDetail}</td> <td> <a href="${path}/paper/toUpdatePaper?id=${paper.paperId}">更改</a> | <a href="<%=appPath%>/paper/del/${paper.paperId}">删除</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div> </div>
updataPaper
[code]<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <html> <head> <title>修改论文</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- 引入 Bootstrap --> <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> 基于SSM框架的管理系统:简单实现增、删、改、查。 </h1> </div> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <div class="page-header"> <h1> <small>修改论文</small> </h1> </div> </div> </div> <form action="" name="userForm"> <input type="hidden" name="paperId" value="${paper.paperId}"/> 论文名称:<input type="text" name="paperName" value="${paper.paperName}"/> 论文数量:<input type="text" name="paperNum" value="${paper.paperNum}"/> 论文详情:<input type="text" name="paperDetail" value="${paper.paperDetail }"/> <input type="button" value="提交" οnclick="updatePaper()"/> </form> <script type="text/javascript"> function updatePaper() { var form = document.forms[0]; form.action = "<%=basePath %>paper/updatePaper"; form.method = "post"; form.submit(); } </script> </div>
执行后打开相应界面
相关文章推荐
- IDEA+Maven 整合SSM框架实现简单的增删改查
- IDEA+Maven 整合SSM框架实现简单的增删改查
- idea+Maven整合SSM框架实现简单增删改查
- IDEA+Maven 整合SSM框架实现简单的增删改查
- IDEA+Maven 整合SSM框架实现简单的增删改查
- (超详细、适合新手入门)IDEA+Maven 整合SSM框架实现简单的增删改查
- 中软实习第四天:在IDEA+MAVEN的环境下使用SSM框架实现简单的数据库的增删改查(代码实现)
- 用IDEA和Maven来整合SSM框架实现增删查改
- 利用IDEA+MAVEN,构建简单的SSM框架,以及实现对数据库的增删查改
- idea+maven+mysql搭建SSM框架实现简单的增删查改
- IDEA+Maven 整合SSM框架实现简单的查询
- IDEA实现SSM框架下简单的增删查改
- SSM框架整合,SSM简单应用,SSM实现增删查改,SSM入门,SSM整合源码下载
- 20190629-IDEA+SSM 搭建好SSM框架后实现简单的增删查改
- SSM框架整合实现增删改查(简单的实现)
- 使用idea+maven+mysql+tomcat搭建简单的增删查改ssm框架系统的企业版写法
- 使用idea+maven+mysql+tomcat搭建简单的增删查改ssm框架系统
- 详细记录->使用Maven+SSM框架,实现单表简单的增删改查
- SSM框架整合,SSM简单应用,SSM实现增删查改,SSM入门,SSM整合源码下载(转)
- idea+maven构建ssm框架并实现增删查改登录的功能