当前位置:网站首页>Teach you to play with SSM framework
Teach you to play with SSM framework
2022-06-11 23:40:00 【Enabling elder martial brother】
Catalog
Development tools and project structure
IDEA+Maven Build project skeleton
2. Add the required files to the new project / Folder
The database for MySQL 5.7 Create table statement
stay pojo New in package Paper.java
stay service New interface in package PaperService
stay dao New interface in package PaperDao.java
stay controller New in package PaperController.java
spring-dao.xml:(spring-mybatis Consolidation profile )
spring-mvc.xml:(spring mvc The configuration file )
spring-service.xml:(service Layer configuration file )
stay log4j.properties Configure log settings in file
stay mybatis-config.xml Configuration in file mybtis frame
index.jsp The file in WEB-INF/jsp New under package addPaper,jsp , appPaper.jsp , updatePaper.jsp
utilize tomcat Project deployment
Paper modification interface :
Preface
In the current enterprise applications ,Spring The whole family bucket frame is a must . and Mybatis Framework as a persistence layer framework , Although you need to write it yourself SQL sentence , But its support for high concurrency and high response , And dynamic SQL And dynamic binding support makes it stand out .
therefore SSM frame (Spring + Spring MVC +Mybatis) Gradually replaced SSH The framework has become a more commonly used framework at present . This article USES the IDEA, utilize Maven Management project , Integrate SSM Framework to build a thesis management system , To achieve a simple increase in 、 Delete 、 Change 、 check . Step by step , Rich explanations , Perfect for beginners .

SpringMVC summary
be familiar with MVC All of my classmates know that ,MVC namely model( Model )、view( View )、controller( control ), Using a business logic , data , The separation of interface display makes the development more convenient and efficient , With low coupling , High reusability , Maintainability and other advantages . therefore ,SpringMVC It is divided into user interface layer (view)、web layer (controller)、 Domain model layer (model).
User interface layer : There are two important interfaces org.springframework.web.servlet.View The interface presents web View or page of the application , It is responsible for converting the result of the client request operation into a form visible to the client . Generally speaking, it is the display of the page ,springmvc Support JSP、Freemarker、Velocity、XSTL、JasperReport、Excel and PDF. org.springframework.web.servlet.viewResolver Provides an indirect layer ,ViewResolver Provides the mapping between view instances and logical names . for example , A file named /WEB-INF/jsp/success.jsp Of jsp page , adopt ”success” The name is quoted , Decouple view and code references .
web layer : key word Controller、ModelAndView springmvc Provides a org.springframework.web.servlet.mvc.Controller Interfaces and others .Controller Responsible for receiving HttpServletRequest and HttpServletResponse, Navigate the request to the method of the specified path , And assembled a ModelAndView, Contains a corresponding all data map And one. view The name of the reference .
Domain model layer : It is the object model of customer and system interaction use ORM The framework makes the object model interact with the database object relationship , That's what we understand POJO object .

MyBatis summary
MyBatis Is to support the general SQL Inquire about , Excellent persistence layer framework for stored procedures and advanced mappings . MyBatis Eliminated almost all of them JDBC Manual setting of code and parameters and retrieval of result sets . MyBatis Easy to use XML Or annotations for configuring and raw mapping , The interface and Java Of POJOs(Plain Old Java Objects, ordinary Java object ) Maps to records in the database . Mybatis Divided into three layers :
API The interface layer : Interface provided for external use API, Developers through these local API To manipulate the database . As soon as the interface layer receives the call request, it will call the data processing layer to complete the specific data processing .
Data processing layer : Be responsible for specific SQL lookup 、SQL analysis 、SQL Execute and execute result mapping processing, etc . Its main purpose is to complete a database operation according to the call request .
Foundation support layer : Responsible for the most basic functional support , Including connection management 、 Business management 、 Configure load and cache handling , These are all common things , Extract them as the most basic components . For the upper layer of data processing layer to provide the most basic support .
Development tools and project structure
- IntelliJ IDEA Ultimate 2017.2.2
- Apache-tomcat-9.0.5
- JDK 1.8.0_121
- MySQL 5.7
- Maven 3.3.9

IDEA+Maven Build project skeleton
1. newly build Maven project
Click on File -> New -> Project -> Maven -> Check Create from archetype -> choice maven-archetype-webapp ( Be careful : Don't choose the above one by mistake cocoom-22-archetype-webapp)


In the pop-up new project Fill in tab GroupId and Artifactid, among GroupID Is the unique identifier of the project organization , Actual correspondence JAVA Structure of the package for , yes main Directory java Directory structure of ,ArtifactID Is the unique identifier of the project , Name of actual corresponding item , Is the name of the project root . For introductory exercises , These two items can be filled in at will .

After clicking on next choice Maven edition ( among IDEA Professional version Maven, You can also choose your own download maven). Then fill in the project name and project address , Click when finished Finish, Finish creating the project skeleton .

2. Add the required files to the new project / Folder
The project after creation is as shown in the figure , We need to create some new directories on top of that .
Create a new one at the root of the project target Folder , The system automatically sets it to “Excluded”

stay src/main New under the directory Directory:“java”, And set it to “Source Root”( namely : Default code file source directory for this project )


I just created it java New under file “com” package , And then com Four new packages under the package , Named as :pojo,service,dao,controller.( If the package names shown in the figure below overlap , You can click the icon shown in the figure , take “Hide empty middle package Cancel it ”)

Four new packages above :pojo,service,dao,controller, They are stored separately :
- pojo: Store custom java class . Such as :paper class ,user class ,book Class etc. , The property of each class is set to private, And provide public Attribute getter/setter Methods for external access
- service: Defining interfaces , Include the functions provided by the system .( After that, I will service New under package impl package ).
- dao: Defining interfaces , Contains functions to interact with the database .
- controller: controller , Responsible for receiving page requests , Forwarding and processing .
stay resource Package under the new Directory:“mapper”( To hold xxxMapper.xml file ) and “spring”( To hold spring-xxx.xml The configuration file ).
New file :“jdbc.properties”(mysql Database configuration file ),”log4j.properties”( Log output profile ),”mybatis-config.xml”(mybatis Framework configuration file ).

stay web-inf New under the directory “jsp” package , Deposit xxx.jsp display .
The supplementary project directory is shown in the figure below , So far, the skeleton of the project has been built , Start writing code to add, delete, modify, and check .

3. Customize Paper class
Before that, we need to pom.xml File , Required to configure the project in this file jar package .
pom.xml
<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>com</groupId>
<artifactId>first</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>
<!-- unit testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- The first part :Spring To configure -->
<!-- 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>
<!-- The second part :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>
<!-- The third part : Database and mybatis -->
<!-- database -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<!-- Database connection pool -->
<dependency>
<groupId>com.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 Integrated package -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- The fourth part : journal -->
<!-- Realization slf4j Interface and integration -->
<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>The database for MySQL 5.7 Create table statement
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `paper`
-- ----------------------------
DROP TABLE IF EXISTS `paper`;
CREATE TABLE `paper` (
`paper_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'paperID',
`name` varchar(100) NOT NULL COMMENT 'paper name ',
`number` int(11) NOT NULL COMMENT 'paper Number ',
`detail` varchar(200) NOT NULL COMMENT 'paper describe ',
PRIMARY KEY (`paper_id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='paper surface ';
-- ----------------------------
-- Records of paper
-- ----------------------------
INSERT INTO `paper` VALUES ('1', ' machine learning ', '2', 'mlmlmlml');
INSERT INTO `paper` VALUES ('2', ' Deep learning ', '3', 'dldldl');
INSERT INTO `paper` VALUES ('3', ' big data ', '4', 'bdbdbd');stay pojo New in package Paper.java
package com.pojo;
public class Paper {
private long paperId;
private String paperName;
private int paperNum;
private String paperDetail;
public long getPaperId() {
return paperId;
}
public void setPaperId(long paperId) {
this.paperId = paperId;
}
public String getPaperName() {
return paperName;
}
public void setPaperName(String paperName) {
this.paperName = paperName;
}
public int getPaperNum() {
return paperNum;
}
public void setPaperNum(int paperNum) {
this.paperNum = paperNum;
}
public String getPaperDetail() {
return paperDetail;
}
public void setPaperDetail(String paperDetail) {
this.paperDetail = paperDetail;
}
}among getter/setter Method can be used after defining private properties IDEA Shortcut keys provided :ALT+Insert For quick addition


stay service New interface in package PaperService
package com.service;
import com.pojo.Paper;
import java.util.List;
public interface PaperService {
int addPaper(Paper paper);
int deletePaperById(long id);
int updatePaper(Paper paper);
Paper queryById(long id);
List<Paper> queryAllPaper();
}stay service Package under the new impl package , And create a new one in this package PaperServiceImpl.java
package com.service.impl;
import com.pojo.Paper;
import com.dao.PaperDao;
import com.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PaperServiceImpl implements PaperService {
@Autowired
private PaperDao paperDao;
@Override
public int addPaper(Paper paper) {
return paperDao.addPaper(paper);
}
@Override
public int deletePaperById(long id) {
return paperDao.deletePaperById(id);
}
@Override
public int updatePaper(Paper paper) {
return paperDao.updatePaper(paper);
}
@Override
public Paper queryById(long id) {
return paperDao.queryById(id);
}
@Override
public List<Paper> queryAllPaper() {
return paperDao.queryAllPaper();
}
}stay dao New interface in package PaperDao.java
package com.dao;
import com.pojo.Paper;
import java.util.List;
public interface PaperDao {
int addPaper(Paper paper);
int deletePaperById(long id);
int updatePaper(Paper paper);
Paper queryById(long id);
List<Paper> queryAllPaper();
}stay controller New in package PaperController.java
package com.controller;
import com.pojo.Paper;
import com.service.PaperService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/paper")
public class PaperController {
@Autowired
private PaperService paperService;
@RequestMapping("/allPaper")
public String list(Model model) {
List<Paper> list = paperService.queryAllPaper();
model.addAttribute("list", list);
return "allPaper";
}
@RequestMapping("toAddPaper")
public String toAddPaper() {
return "addPaper";
}
@RequestMapping("/addPaper")
public String addPaper(Paper paper) {
paperService.addPaper(paper);
return "redirect:/paper/allPaper";
}
@RequestMapping("/del/{paperId}")
public String deletePaper(@PathVariable("paperId") Long id) {
paperService.deletePaperById(id);
return "redirect:/paper/allPaper";
}
@RequestMapping("toUpdatePaper")
public String toUpdatePaper(Model model, Long id) {
model.addAttribute("paper", paperService.queryById(id));
return "updatePaper";
}
@RequestMapping("/updatePaper")
public String updatePaper(Model model, Paper paper) {
paperService.updatePaper(paper);
paper = paperService.queryById(paper.getPaperId());
model.addAttribute("paper", paper);
return "redirect:/paper/allPaper";
}
}stay resource/mapper Package under the new PaperMapper.xml(mybatis frame mapper Agent development profile )
<?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.dao.PaperDao">
<resultMap type="Paper" id="paperResultMap" >
<id property="paperId" column="paper_id"/>
<result property="paperName" column="name"/>
<result property="paperNum" column="number"/>
<result property="paperDetail" column="detail"/>
</resultMap>
<insert id="addPaper" parameterType="Paper">
INSERT INTO paper(paper_id,name,number,detail) VALUE (#{paperId},#{paperName}, #{paperNum}, #{paperDetail})
</insert>
<delete id="deletePaperById" parameterType="long">
DELETE FROM paper WHERE paper_id=#{paperID}
</delete>
<update id="updatePaper" parameterType="Paper">
UPDATE paper
SET NAME = #{paperName},NUMBER = #{paperNum},detail = #{paperDetail}
WHERE paper_id = #{paperId}
</update>
<select id="queryById" resultMap="paperResultMap" parameterType="long">
SELECT paper_id,name,number,detail
FROM paper
WHERE paper_id=#{paperId}
</select>
<select id="queryAllPaper" resultMap="paperResultMap">
SELECT paper_id,name,number,detail
FROM paper
</select>
</mapper>stay resource/spring Create a new profile under the package :spring-dao.xml , spring-mvc.xml , spring-service.xml

spring-dao.xml:(spring-mybatis Consolidation profile )
<?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"
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">
<!-- Configuration integration mybatis The process -->
<!-- 1. Configuration database related parameters properties Properties of :${url} -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2. Database connection pool -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- Configure connection pool properties -->
<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 Private properties of connection pool -->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!-- Do not automatically close the connection commit -->
<property name="autoCommitOnClose" value="false"/>
<!-- Get connection timeout -->
<property name="checkoutTimeout" value="10000"/>
<!-- Number of retries when get connection failed -->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!-- 3. To configure SqlSessionFactory object -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- Inject the database connection pool -->
<property name="dataSource" ref="dataSource"/>
<!-- To configure MyBaties Global profile :mybatis-config.xml -->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<!-- scanning pojo package Use the alias -->
<property name="typeAliasesPackage" value="com.pojo"/>
<!-- scanning sql The configuration file :mapper Needed xml file -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- 4. Configure scan Dao Interface package , Dynamic implementation Dao Interface , Injection into spring In the container -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- Inject sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!-- Give need to scan Dao Interface package -->
<property name="basePackage" value="com.dao"/>
</bean>
</beans>spring-mvc.xml:(spring mvc The configuration file )
<?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
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- To configure SpringMVC -->
<!-- 1. Turn on SpringMVC Annotation model -->
<!-- Simplified configuration :
(1) Automatic registration DefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter
(2) Provide some columns : Data binding , Of numbers and dates format @NumberFormat, @DateTimeFormat, xml,json Default read / write support
-->
<mvc:annotation-driven />
<!-- 2. Static resource default servlet To configure
(1) Add processing to static resources :js,gif,png
(2) Allow to use "/" Make an overall map
-->
<mvc:default-servlet-handler/>
<!-- 3. To configure jsp Show ViewResolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 4. scanning web dependent bean -->
<context:component-scan base-package="com.controller" />
</beans>spring-service.xml:(service Layer configuration file )
<?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: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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- scanning service All types of annotations used under the package -->
<context:component-scan base-package="com.service" />
<!-- Configure transaction manager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- Inject the database connection pool -->
<property name="dataSource" ref="dataSource" />
</bean>
<!-- Configure annotation based declarative transactions -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>stay jdbc.properties Configuration in file mysql database ( Database name here 、 Table name , user name , Remember to change the password !!!)
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/papersystem?useUnicode=true&characterEncoding=utf8
jdbc.username=root
jdbc.password=12345678stay log4j.properties Configure log settings in file
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%nstay mybatis-config.xml Configuration in file mybtis frame
<?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>
<!-- Configure global properties -->
<settings>
<!-- Use jdbc Of getGeneratedKeys Get database auto increment primary key value -->
<setting name="useGeneratedKeys" value="true" />
<!-- Replace column names with column aliases Default :true -->
<setting name="useColumnLabel" value="true" />
<!-- Turn on hump naming conversion :Table{create_time} -> Entity{createTime} -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>To configure web.xml file
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<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_3_1.xsd"
version="3.1" metadata-complete="true">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- To configure springMVC Profile to load
spring-dao.xml,spring-service.xml,spring-mvc.xml
Mybatis - > spring -> springmvc
-->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<!-- Match all requests by default -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<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>
</web-app>index.jsp The file in WEB-INF/jsp New under package addPaper,jsp , appPaper.jsp , updatePaper.jsp
allPaper.jsp
<%@ 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 list </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- introduce 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>
be based on SSM Framework management system : Simple implementation 、 Delete 、 Change 、 check .
</h1>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small> List of papers —— Show all papers </small>
</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 column">
<a class="btn btn-primary" href="${path}/paper/toAddPaper"> newly added </a>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-hover table-striped">
<thead>
<tr>
<th> Thesis number </th>
<th> Title of thesis </th>
<th> Number of papers </th>
<th> Paper details </th>
<th> operation </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}"> change </a> |
<a href="<%=appPath%>/paper/del/${paper.paperId}"> Delete </a>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>addPaper,jsp: Paper add page
<%@ 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> New papers </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- introduce 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>
be based on SSM Framework management system : Simple implementation 、 Delete 、 Change 、 check .
</h1>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small> New papers </small>
</h1>
</div>
</div>
</div>
<form action="" name="userForm">
Title of thesis :<input type="text" name="paperName"><br><br><br>
Number of papers :<input type="text" name="paperNum"><br><br><br>
Paper details :<input type="text" name="paperDetail"><br><br><br>
<input type="button" value=" add to " onclick="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>updatePaper.jsp: Paper change interface
<%@ 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> Modify the paper </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- introduce 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>
be based on SSM Framework management system : Simple implementation 、 Delete 、 Change 、 check .
</h1>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="page-header">
<h1>
<small> Modify the paper </small>
</h1>
</div>
</div>
</div>
<form action="" name="userForm">
<input type="hidden" name="paperId" value="${paper.paperId}"/>
Title of thesis :<input type="text" name="paperName" value="${paper.paperName}"/>
Number of papers :<input type="text" name="paperNum" value="${paper.paperNum}"/>
Paper details :<input type="text" name="paperDetail" value="${paper.paperDetail }"/>
<input type="button" value=" Submit " onclick="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>utilize tomcat Project deployment
- download install tomcat:tomcat Download address
- IDEA To configure tomcat:
Click on the Run Options , choice Edit Configuration

choice default -> tomcat -> local Select download install to local tomcat The address of the server .

Switch to Deployment Options page Click on + Number selection Arctifact

add to Project name :war exploded pack

Last in Application context Choose from blank That item , Click on Apply application .

Finally switch to index.jsp Interface , Right click to run project

Operation interface
Paper list interface :

New paper interface :

Paper modification interface :

thus , utilize IDEA+Maven+SSM Framework implementation adds 、 Delete 、 Change 、 Query function has been built !
边栏推荐
- El select drop-down box style combined with El table (pseudo) combined with drop-down selection
- 2022 low voltage electrician certificate and online simulation examination
- Application of Lora technology in long distance wireless transmission of water meter reading
- What are the pitfalls of redis's current network: using a cache and paying for disk failures?
- 2022年安全员-B证理论题库及模拟考试
- What is webstorage? And cookies
- Jenkins basic configuration
- (counting class +dp) acwing 900 Integer partition
- (greedy + longest ascending subsequence) acwing 896 Longest ascending subsequence II
- Data processing and visualization of machine learning [iris data classification | feature attribute comparison]
猜你喜欢

(dp) acwing 902. Minimum editing distance

(dp+ longest common subsequence) acwing 897 Longest common subsequence

(greedy + longest ascending subsequence) acwing 896 Longest ascending subsequence II

2022年安全员-B证理论题库及模拟考试

(simple statistics) acwing 3404 Who are your potential friends

Fonctionnement de la plate - forme d'examen de simulation pour les agents de sécurité - Questions d'examen de certificat a en 2022

RF中使用reuqests的两种方式

移印工艺流程及应用注意事项

2022 high place installation, maintenance and removal of simulated examination platform for operation certificate examination question bank

HMS core shows the latest open capabilities in mwc2022, helping developers build high-quality applications
随机推荐
04 automatic learning rate - learning notes - lihongyi's in-depth learning 2021
(dp) acwing 899. Edit distance
Remix localization, loading local contract file, local link Remix
Share a treasure website necessary for new media operation for free
(interval DP | dfs+ memory) acwing 282 Stone merging
一文读懂Logstash原理
Mysql5 and mysql8 are installed at the same time
(dp+ longest common subsequence) acwing 897 Longest common subsequence
CD process
Two way leading circular linked list (C language)
产品力进阶新作,全新第三代荣威RX5盲订开启
What are the pitfalls of redis's current network: using a cache and paying for disk failures?
(counting class +dp) acwing 900 Integer partition
New Year Countdown JS case
Altium designer工程下多个原理图和PCB图的一一对应
【delphi】判断文件的编码方式(ANSI、Unicode、UTF8、UnicodeBIG)
How many steps does it take for C language to become Fibonacci number
A new product with advanced product power, the new third generation Roewe rx5 blind subscription is opened
Fonctionnement de la plate - forme d'examen de simulation pour les agents de sécurité - Questions d'examen de certificat a en 2022
On the knowledge points of cookie attributes and the differences between webstorage and cookies?