1. Basic Concepts

1.1 the Spring

Spring is an open source framework. Spring is a lightweight Java development framework that started in 2003. Derived from some of the concepts and prototypes elaborated by Rod Johnson in his book Expert One-On-One J2EE Development and Design. It was created to address the complexity of enterprise application development. Spring uses basic Javabeans to do things that were previously only possible with EJBs. However, Spring’s use is not limited to server-side development. Any Java application can benefit from Spring in terms of simplicity, testability, and loose coupling. In simple terms, Spring is a lightweight Inversion of Control (IoC) and AOP oriented container framework.

1.2 for SpringMVC

Spring MVC is a successor to the Spring Framework and has been integrated into Spring Web Flow. Spring MVC separates the roles of controller, model object, dispatcher, and handler object, which makes them easier to customize.

1.3 MyBatis

MyBatis is an open source project of Apache called iBatis. In 2010, this project was migrated to Google Code by Apache Software Foundation and renamed as MyBatis. MyBatis is a Java-based persistence layer framework. MyBatis eliminates almost all manual setting of JDBC code and parameters as well as retrieval of result sets. MyBatis uses simple XML or annotations for configuration and raw mapping to map interfaces and Java’s POJOs (Plain Old Java Objects) to records in the database.

Second, SSM integration

The following is a brief introduction to the integration of the three frameworks. In this integration, I divided two configuration files, namely spring-Mybatis. XML, which contains the configuration files of Spring and Mybatis, and another one is the configuration file of Spring-MVC. JDBC. Propertis and log4j. Properties.

2.1 Maven imports required JAR packages

Introduce jar packages in POM.xml

The < 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" > The < modelVersion > 4.0.0 < / modelVersion > < groupId > com. Javen. Maven01 < / groupId > < artifactId > maven01 < / artifactId > <packaging> War </packaging> <version>0.0.1-SNAPSHOT</version> <name> Maven01 Maven01 Webapp</name> <url>http://maven.apache.org</url><properties> <! --> <spring.version>4.0.2.RELEASE</spring.version> <! <mybatis. Version >3.2.6</mybatis. Version > <! -- Log4j log file management package version --> <slf4j.version>1.7.7</slf4j.version> <log4j.version>1.2.17</log4j.version> </properties> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <! <scope>test</scope> </dependency> <! Javax. servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> --> <! <dependency> <groupId>org. springFramework </groupId> <artifactId> Spring-core </artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</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-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <! Mybatis </groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <! Mybatis </groupId> <artifactId>mybatis </artifactId> The < version > 1.2.2 < / version > < / dependency > <! <dependency> <groupId> Javax </groupId> <artifactId> Javaee - API </artifactId> <version>7.0</version> </dependency> <! <dependency> <groupId> Mysql </groupId> <artifactId>mysql-connector-java</artifactId> The < version > 5.1.36 < / version > < / dependency > <! DBCP jar package; > <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> The < version > 1.2.2 < / version > < / dependency > <! JSTL </artifactId> JSTL </artifactId> <version>1.2</version> </dependency> <! -- Log file management package --> <! -- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <! -- Format the object, Alibaba </groupId> <artifactId>fastjson</artifactId> <version>1.1.41</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <! -- log end --> <! <dependency> <groupId>org.codehaus. Jackson </groupId> <artifactId>jackson-mapper-asl</artifactId> The < version > 1.9.13 < / version > < / dependency > <! <dependency> <groupId> Commons -fileupload</groupId> <artifactId> Commons -fileupload</artifactId> <version>1.3.1</version> </dependency> <dependency> <groupId> Commons -io</groupId> <artifactId> < version > 2.4 < / version > < / dependency > < the dependency > < groupId > Commons - codec < / groupId > <artifactId> Commons -codec</artifactId> <version>1.9</version> </dependency> </dependencies> </dependencies> <build> <finalName>maven01</finalName> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> < artifactId > jetty maven - plugin < / artifactId > < version > 9.2.8. V20150217 < / version > < configuration > < httpConnector > <port>80</port> </httpConnector> <stopKey>shutdown</stopKey> <stopPort>9966</stopPort> </configuration> </plugin> </plugins> </build></project>Copy the code

2.2 integration for SpringMVC

2.2.1 configuration spring – the MVC. XML

Configuration inside the notes are also very detailed, mainly automatic scan controller, view mode, the start of the notes these three.

<? The 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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <! <context:component-scan base-package="com.javen.controller" /> <! MVC :annotation-driven/> <! < MVC :resources location="/resources/**" mapping="/resources"/> <! -- Avoid AJAX execution in IE Returns a JSON download file -- > < bean id = "mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html; charset=UTF-8</value> </list> </property> </bean> <! -- Enable annotations for SpringMVC To complete the request and annotate the POJO mapping - > < bean class = "org. Springframework. Web. Servlet. MVC. The annotation. AnnotationMethodHandlerAdapter" > <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /> <! </list> </property> </bean> <! -- Configuration file upload, if you do not use file upload can not configure, of course, if not, <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <! Property name="defaultEncoding" value=" UTF-8 "/> <! <property name="maxUploadSize" value="10485760000" /> <! <property name="maxInMemorySize" value="40960" /> <! <property name="resolveLazily" value="true"/> </bean> <! -- Configure the ViewResolver. Multiple ViewResolvers can be used. Sort using the order attribute. InternalResourceViewResolver last - > < bean class = "org. Springframework. Web. Servlet. The ContentNegotiatingViewResolver" > <property name="order" value="1"></property> <property name="mediaTypes"> <map> <! Tell the view parser, The returned type is JSON format --> <entry key=" JSON "value="application/json" /> <entry key=" XML" value="application/ XML "/> <entry key="htm" value="text/htm" /> </map> </property> <property name="defaultViews"> <list> <! - ModelAndView data into a JSON - > < bean class = "org. Springframework. Web. Servlet. The JSON. MappingJacksonJsonView" / > < / list > </property> <property name="ignoreAcceptHeader" value="true"></property> </bean> <! - define the jump of the file before the suffix, view mode configuration - > < bean class = "org. Springframework. Web. Servlet. The InternalResourceViewResolver" > <! The action method return string is automatically prefixed and postfixed. <property name="prefix" value="/ web-INF/JSP /" /> <property name="suffix" value=".jsp" /> </bean> </beans>Copy the code

2.2.2 Configuring the web. XML file

The Servlet of Spring-MVC is configured to accomplish the integration of SpringMVC+MAVEN. web.xml

<? The 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" version = "3.0" > <display-name>Archetype Created Web Application</display-name> <! -- Spring and Mybatis configuration files --> <! -- <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mybatis.xml</param-value> </context-param> --> <! -- encodingFilter --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <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> <! -- Spring listener --> <! -- <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> --> <! Prevent Spring memory overflow listener --> <! -- <listener> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> --> <! -- Spring MVC servlet --> <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:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> </servlet> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <! *. Do, *. Struts --> <url-pattern>/</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> </web-app>Copy the code

2.2.3 Log4j Configuration

Log4j is an open source project of Apache. By using Log4j, we can control the destination of log messages to the console, files, GUI components, even the socket server, NT event logger, UNIX Syslog daemon, etc. We can also control the output format of each log; By defining the level of each log message, we can more carefully control the log generation process.

The configuration of Log4j is simple and generic, so here is a basic configuration that doesn’t need to be changed much in other projects

Log4j. RootLogger = INFO, the Console, the File # define log output destination for Console log4j. Appender. The Console = org.. Apache log4j. ConsoleAppender . Log4j appenders. Console. Target = System. # out the flexibility to specify the log output format, The following line is to specify the specific format of the log4j. Appender. Console. The layout = org.. Apache log4j. PatternLayout Log4j. Appender. Console. Layout. ConversionPattern = % [c] - % m % n # File size to specified size to create a new File log4j. Appender. The File = Org, apache log4j. RollingFileAppender # log4j. The output directory appender. File. The File = logs/SSM. Log # definition File maximum size . Log4j appenders. File. MaxFileSize = 10 MB # output so log, Said if switch to the DEBUG output above the DEBUG level logs log4j. Appender. File. The Threshold = ALL log4j. Appender. File. The layout = org.. Apache log4j. PatternLayout  log4j.appender.File.layout.ConversionPattern =[%p] [%d{yyyy-MM-dd HH:mm:ss}][%c]%m%nCopy the code

2.2.4 Using Jetty tests

package com.javen.model; public class User { private Integer id; private String userName; private String password; private Integer age; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName == null ? null : userName.trim(); } public String getPassword() { return password; } public void setPassword(String password) { this.password = password == null ? null : password.trim(); } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "User [id=" + id + ", userName=" + userName + ", password=" + password + ", age=" + age + "]"; }} package com.javen.controller; import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.javen.model.User; @Controller @RequestMapping("/user") // /user/**public class UserController { private static Logger log=LoggerFactory.getLogger(UserController.class); // /user/test? id=1 @RequestMapping(value="/test",method=RequestMethod.GET) public String test(HttpServletRequest request,Model model){  int userId = Integer.parseint(request.getParameter("id")); System.out.println("userId:"+userId); User user=null; if (userId==1) { user = new User(); user.setAge(11); user.setId(1); user.setPassword("123"); user.setUserName("javen"); } log.debug(user.toString()); model.addAttribute("user", user); return "index"; }}Copy the code

The SpringMVC+Maven integration is complete

2.3 Integration of Spring and MyBatis

Uncomment the code in 3.2.2 web.xml

2.3.1 Creating a JDBC property file

JDBC. The properties (file code is modified to utf-8) driver = com. Mysql. JDBC. Driverurl = JDBC: mysql: / / localhost: 3306 / mavenusername = rootpassword = root InitialSize =0 maxActive=20 maxIdle=20 minIdle=1 maxWait=60000Copy the code

2.3.2 Establishing the spring-Mybatis. XML configuration file

This file is used to complete the integration of Spring and Mybatis. There are not many lines of configuration, mainly automatic scanning, automatic injection, configuration of the database. Notes are also very detailed, you will understand. spring-mybatis.xml

<? The 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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <! <context:component-scan base-package="com.javen" /> <! <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:jdbc.properties" /> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${driver}" /> <property name="url" value="${url}" /> <property name="username" value="${username}" /> <property name="password" value="${password}" /> <! Property name="initialSize" value="${initialSize}"></property> <! --> <property name="maxActive" value="${maxActive}"> <property name="maxIdle" value="${maxIdle "></property> <! <property name="minIdle" value="${minIdle "></property> <! Property name="maxWait" value="${maxWait}"></property> </bean> <! -- Perfect integration of Spring and MyBatis Don't need mybatis configuration mapping file - > < bean id = "sqlSessionFactory" class = "org. Mybatis. Spring. SqlSessionFactoryBean" > < property name="dataSource" ref="dataSource" /> <! - automatic scanning mapping. The XML file - > < property name = "mapperLocations" value = "classpath: com/javen/mapping / *. XML" > < / property > < / bean > <! -- DAO interface package name, Spring will automatically find below class -- > < bean class = "org. Mybatis. Spring. Mapper. MapperScannerConfigurer" > < property name = "basePackage" value="com.javen.dao" /> <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property> </bean> <! Transaction Manager, use JtaTransactionManager for global tx --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> </beans>Copy the code

2.4 the JUnit test

After the above steps, we have completed the integration of Spring and MyBatis, so we can write a test code to see if it works.

2.4.1 Creating a Test Table

Since we need to test, then we need to build a test table in the database, this table is built very simple, SQL statement:

-- ------------------------------ Table structure for `user_t`-- ----------------------------DROP TABLE IF EXISTS `user_t`; CREATE TABLE `user_t` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(40) NOT NULL, `password` varchar(255) NOT NULL, `age` int(4) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -- ------------------------------ Records of user_t-- ----------------------------INSERT INTO `user_t` VALUES ('1', 'Test ', '345', '24'); INSERT INTO `user_t` VALUES ('2', 'javen', '123', '10');Copy the code

2.4.2 Create code automatically with MyBatis Generator

This automatically creates the entity class, MyBatis mapping file, and THE DAO interface from the table. Of course, I’m in the habit of changing the generated interface name to IUserDao instead of using the UserMapper it generated directly. You don’t have to change it if you don’t want the trouble. Copy the files to the project when you are done.

2.4.3 Establishing the Service Interface and implementation class

The specific content is given below:

IUserService.javepackage com.javen.service; import com.javen.model.User; public interface IUserService { public User getUserById(int userId); }Copy the code

UserServiceImpl.java

package com.javen.service.impl; import javax.annotation.Resource; import org.springframework.stereotype.Service; import com.javen.dao.IUserDao; import com.javen.model.User; import com.javen.service.IUserService; @Service("userService") public class UserServiceImpl implements IUserService { @Resource private IUserDao userDao; public User getUserById(int userId) { // TODO Auto-generated method stub return this.userDao.selectByPrimaryKey(userId);  }}Copy the code

2.4.4 Creating a test class

The test class is created in SRC /test/ Java. The comment section of the test class below is a common test method when Spring is not used. If you are using Spring, you can use annotations to import configuration files and classes, and then inject service interface objects to test.

If the test is successful, Spring and Mybatis have been integrated successfully. The output is printed to the console using Log4j.

package com.javen.testmybatis; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.alibaba.fastjson.JSON; import com.javen.model.User; import com.javen.service.IUserService; @ RunWith (SpringJUnit4ClassRunner. Class) / / said inherited SpringJUnit4ClassRunner class @ ContextConfiguration (locations = {"classpath:spring-mybatis.xml"}) public class TestMyBatis { private static Logger logger = Logger.getLogger(TestMyBatis.class); // private ApplicationContext ac = null; @Resource private IUserService userService = null; // @Before // public void before() { // ac = new ClassPathXmlApplicationContext("applicationContext.xml"); // userService = (IUserService) ac.getBean("userService"); // } @Test public void test1() { User user = userService.getUserById(1); // System.out.println(user.getUserName()); // logger.info(" value: "+ user.getUsername ()); logger.info(JSON.toJSONString(user)); }}Copy the code

2.4.5 Creating the UserController class

UserController. Java controller

package com.javen.controller; import java.io.File; import java.io.IOException; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; 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 org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import com.javen.model.User; import com.javen.service.IUserService; @Controller @RequestMapping("/user") // /user/**public class UserController { private static Logger log=LoggerFactory.getLogger(UserController.class); @Resource private IUserService userService; // /user/test? id=1 @RequestMapping(value="/test",method=RequestMethod.GET) public String test(HttpServletRequest request,Model model){  int userId = Integer.parseint(request.getParameter("id")); System.out.println("userId:"+userId); User user=null; if (userId==1) { user = new User(); user.setAge(11); user.setId(1); user.setPassword("123"); user.setUserName("javen"); } log.debug(user.toString()); model.addAttribute("user", user); return "index"; } // /user/showUser? id=1 @RequestMapping(value="/showUser",method=RequestMethod.GET) public String toIndex(HttpServletRequest request,Model model){ int userId = Integer.parseint(request.getParameter("id")); System.out.println("userId:"+userId); User user = this.userService.getUserById(userId); log.debug(user.toString()); model.addAttribute("user", user); return "showUser"; } // /user/showUser2? id=1 @RequestMapping(value="/showUser2",method=RequestMethod.GET) public String toIndex2(@RequestParam("id") String id,Model model){ int userId = Integer.parseint(id); System.out.println("userId:"+userId); User user = this.userService.getUserById(userId); log.debug(user.toString()); model.addAttribute("user", user); return "showUser"; } // /user/showUser3/{id} @RequestMapping(value="/showUser3/{id}",method=RequestMethod.GET) public String toIndex3(@PathVariable("id")String id,Map<String, Object> model){ int userId = Integer.parseint(id); System.out.println("userId:"+userId); User user = this.userService.getUserById(userId); log.debug(user.toString()); model.put("user", user); return "showUser"; } // /user/{id} @RequestMapping(value="/{id}",method=RequestMethod.GET) public @ResponseBody User getUserInJson(@PathVariable String id,Map<String, Object> model){ int userId = Integer.parseint(id); System.out.println("userId:"+userId); User user = this.userService.getUserById(userId); log.info(user.toString()); return user; } // /user/{id} @RequestMapping(value="/jsontype/{id}",method=RequestMethod.GET) public ResponseEntity<User> getUserInJson2(@PathVariable String id,Map<String, Object> model){ int userId = Integer.parseint(id); System.out.println("userId:"+userId); User user = this.userService.getUserById(userId); log.info(user.toString()); return new ResponseEntity<User>(user,HttpStatus.OK); } @requestMapping (value="/upload") public String showUploadPage(){return "user_admin/file"; } @RequestMapping(value="/doUpload",method=RequestMethod.POST) public String doUploadFile(@RequestParam("file")MultipartFile file) throws IOException{ if (! file.isEmpty()) { log.info("Process file:{}",file.getOriginalFilename()); } FileUtils.copyInputStreamToFile(file.getInputStream(), new File("E:\",System.currentTimeMillis()+file.getOriginalFilename())); return "succes"; }}Copy the code

2.4.6 Creating a JSP page

file.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%><! PUBLIC DOCTYPE HTML "- / / / / W3C DTD HTML 4.01 Transitional / / EN" "http://www.w3.org/TR/html4/loose.dtd" > < HTML > < head > < meta http-equiv="Content-Type" content="text/html; Charset = UTF-8 "><title>Insert title here</title></head><body> <h1> </h1> <form method="post" action="/user/doUpload" Enctype ="multipart/form-data"> < form type="file" name="file"/> < form type="submit" value=" submit" /> </form></body></html>Copy the code

index.jsp

<html><body><h2>Hello World! </h2></body></html>Copy the code

showUser.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < HTML > <title> </title> </head> <body> ${user.userName} </body> </html>Copy the code

So far, the integration of Spring+SpingMVC+ Mybatis has been completed.

Java programmer welfare: Gold nine silver ten, I have experienced the recent year of Java job interview, and some brush interview questions have made a PDF, PDF is free to share with you, pay attention to the private letter I: interview information, free to receive!