- External package dependency introduction
External dependency package introduction can be based on the relevant package name from
Website: http://mvnrepository.com/
Get the dependency introducing statement structure.
See the pom.xml file in ssm-parent for details of the dependency packages for SSM projects.
1.1 Spring framework dependency package introduction
spring-context spring-beans spring-jdbc spring aspects spring-webmvc
1.2 Spring-mybatis dependency package introduction
mybatis mybatis-spring
1.3 database dependency package introduction
mysql-connector-java druid
1.4 redis dependency package introduction
jedis
1.5 Web-related dependency package introduction
jstl servlet-api jsp-api Jackson-databind
1.6 Introduction of other log and public package dependencies
slf4j-log4j12 junit commons-langs commons-io
- Inter-project dependencies and package introduction
ssm-parent implements the introduction of all external dependency packages (1) ssm-commons implements common components, tool classes, etc. (2) ssm-manager actual business management engineering, aggregation engineering, It includes engineering dependencies (1) (3)ssm-manager-pojo (4) ssm-manager-mapper dependency (3) (5) ssm-manager-service dependency (3,4) (6) ssm-manager-controller dependency (3,5)
- A Brief Introduction to Spring
Spring is an open source framework. Spring is a lightweight Java development framework that was created by Rod Johnson in 2003. Simply put, Spring is a layered JavaSE/EEfull-stack (one-stop) lightweight open source framework.
Lightweight - Spring is lightweight in terms of size and overhead. The complete Spring framework can be published in a JAR file of more than 1 MB in size. And Spring's processing overhead is negligible. In addition, Spring is non-intrusive: Typically, objects in Spring applications do not depend on Spring's specific classes.
Inversion of control —— Spring uses a method called control inversion.( IoC ) Technology promotes low coupling. When IoC is applied, other objects that an object depends on are passed in passively, rather than creating or searching the dependent object itself. You can think of IoC as the opposite of JNDI -- not that objects look for dependencies from containers, but that containers actively pass dependencies to objects without waiting for object requests to initialize them.
Face-oriented -- Spring provides Face-Oriented Programming Rich support that allows for separation of application business logic from system-level services such as auditing and affair(transaction ) Management) Cohesiveness Development. Application object Just implement what they should do -- complete business logic -- that's all. They are not responsible (or even conscious) for other system-level concerns, such as logging or transaction support.
Container - Spring contains and manages the configuration and lifecycle of application objects. In this sense, Spring is a container that allows you to configure how each of your beans is created. Based on a prototype, your beans can create a separate instance or generate a new instance every time they are needed. —— And how they relate to each other. However, Spring should not be confused with traditional heavyweight EJB containers, which are often huge and bulky and difficult to use.
Framework - Spring can configure and compose simple components into complex applications. In Spring, application objects are declaratively grouped, typically in an XML file. Spring also provides many basic functions (transaction management, persistence framework integration, etc.), leaving the development of application logic to you.
MVC - Spring's role is integration, but not just integration. Spring framework can be seen as an enterprise solution level framework. The client sends the request, the server controller (implemented by Dispatcher Servlet) completes the transfer of the request, and the controller calls a class Handler Mapping for mapping, which maps the request to the corresponding processor to process the request. Handler Mapping maps requests to the corresponding processor Controller (equivalent to Action) in Spring. If some processor components are written in Spring, the Controller interface is generally implemented. In Controller, some Service or DAO can be invoked for data operation ModelAndView to store the data extracted from DAO, and it can also be stored. Respond to some of the data in the view. If you want to return the processing results to the user, a view component ViewResolver is also provided in the Spring framework. According to the label returned by Controller, the component finds the corresponding view and returns the response response to the user.
All of Spring's features allow you to write cleaner, more manageable, and easier to test code. They also provide basic support for various modules in Spring.
From Baidu Encyclopedia
Summarize a few points:
-
spring is lightweight and develops source code.
-
spring has the characteristics of controlling inversion and dependency injection, transforming active association between classes into passive association, realizing mutual decoupling, and simplifying development through configuration files.
-
aop is oriented to aspect programming, which separates the core business of the system from the service, realizes the decoupling of the code, and realizes the global invocation through aspect, such as log, transaction, etc.
-
It can integrate well with other frameworks, such as mybatis,struts2,hibernate,redis, etc.
Details can be found on the official website: http://spring.io./
- Brief introduction to mybatis
MyBatis is an excellent persistence framework that supports customized SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC code and manual parameter setting and retrieving result sets. MyBatis can use simple XML or annotations to configure and native Map s, mapping interfaces and Java POJOs(Plain Old Java Objects, common Java objects) into records in the database.
Details can be found on the official website: http://www.mybatis.org/mybatis-3/zh/index.html
mybatis's advantage over hibernate
-
mybatis is lightweight, low cost and easy to use.
-
mybatis is semi-automated and related sql needs to be implemented manually.
How mybatis works:
5. Configuration implementation of Spring, mybatis, mysql, etc.
Because ssm-controller in SSM project relies on all modules, in order to facilitate the management of configuration files, the project configuration files are generally placed in the smm-controller directory file.
5.1 All configuration files in the ssm-manager-controller project
db.properties
jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/ussm?characterEncoding=utf-8 jdbc.username=root jdbc.password=root
log4j.pertites
#log4j.rootLogger=DEBUG,INFO,Console,ERROR,stdout log4j.rootLogger=INFO,Console,ERROR,stdout # Druid log4j.logger.druid.sql=DEBUG log4j.logger.druid.sql.DataSource=warn log4j.logger.druid.sql.Connection=warn log4j.logger.druid.sql.Statement=DEBUG log4j.logger.druid.sql.ResultSet=warn log4j.appender.Console=org.apache.log4j.ConsoleAppender log4j.appender.Console.Target=System.out log4j.appender.Console.layout=org.apache.log4j.PatternLayout log4j.appender.Console.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%c]%m%n
SqlMapConfig.xml (refer to the following mybatis configuration document: http://www.mybatis.org/mybatis-3/zh/configuration.html#settings)
<?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> <settings> <!-- Log open --> <setting name="logImpl" value="LOG4J"/> <!-- Level 2 Cache Opening --> <setting name="cacheEnabled" value="true"/> <setting name="lazyLoadingEnabled" value="false"/> <setting name="aggressiveLazyLoading" value="true"/> </settings> </configuration>
applicationContext-mapper.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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd 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-4.1.xsd"> <!-- configuration file --> <context:property-placeholder location="classpath:config/*.properties"/> <!-- data source --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="driverClassName" value="${jdbc.driver}" /> <property name="maxActive" value="10" /> <property name="minIdle" value="5" /> <property name="logAbandoned" value="true" /> </bean> <!-- To configure sqlsessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property> <property name="dataSource" ref="dataSource"></property> </bean> <!-- Configure scan package, load mapper Surrogate object --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.ssm.manager.mapper"></property> </bean> </beans>
applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 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-4.1.xsd"> <!-- Automatic scanning service package --> <context:component-scan base-package="com.ssm.manager.service"></context:component-scan> <import resource="applicationContext-mapper.xml"/> <import resource="applicationContext-trans.xml"/> </beans>
applicationContext-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:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- MVC --> <!-- adopt Web.xml Of DispatcherServlet Load --> <!-- Will automatically register DefaultAnnotationHandlerMapping And AnnotationMethodHandlerAdapter Two bean,yes spring MVC by@Controllers Required to distribute requests --> <!-- <mvc:annotation-driven /> --> <mvc:annotation-driven /> <!--avoid IE implement AJAX Return when JSON Download file appears --> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json; charset=utf-8</value> </list> </property> </bean> <!-- start-up SpringMVC Annotation function to complete requests and annotations POJO Mapping --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /> <!-- JSON Converter --> </list> </property> </bean> <!-- 2. Component Scan Path Configuration Spring The container knows which package paths to scan for classes that can be loaded into the container --> <!-- Multiple Scanning Path Configuration base-package="com.app,com.core,JUnit4" You can also write multiple copies.,Generally write multiple copies directly --> <context:component-scan base-package="com.ssm.manager.*" /> <!-- start-up spring Transaction annotation, $The enablement must be springMVC in,But not in applicationContext.xml Middle configuration,Otherwise, the transaction comment is invalid $ //That is to say, only this line can really open a transaction, annotating @Transaction separately on a class or method is only marked as a transaction and - > <tx:annotation-driven transaction-manager="transactionManager" /> <!-- 3. Processing at the class level@RequestMapping annotation --> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> <!-- Multiple interceptors,Sequential execution --> <!-- <ref bean="SpringMVCInterceptor" /> --> <!-- <ref bean="OpenSessionInViewInterceptor" /> --> </list> </property> </bean> <!-- 4.Processing method level@RequestMapping annotation --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> <property name="conversionService"> <bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean"></bean> </property> </bean> </property> </bean> <!-- 5.Analysis of Model View Names by Adding Prefixes and Suffixes to Model View Names --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/" /> <!-- Give Way ModelAndView("jsp/teacher/listTeachers.jsp") from/WEB-INF/Start under the catalog --> <property name="suffix" value="" /> <!-- <property name="suffix" value=".jsp" /> --> <!-- Spring Internal Resource Resolution Class --> <property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView" /> </bean> <!-- 6.Exception parser --> <bean id="simpleMappingExceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">jsp/common/exception</prop> </props> </property> </bean> </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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://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.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- Transaction Manager --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- data source --> <property name="dataSource" ref="dataSource" /> </bean> <!-- notice --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- Communication behavior --> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="insert*" propagation="REQUIRED" /> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="create*" 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="select*" propagation="SUPPORTS" read-only="true" /> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <!-- section --> <aop:config> <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.ssm.manager.service.*.*(..))" /> </aop:config> </beans>
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="ssm" version="2.5"> <display-name>ssm-manager</display-name> <!-- spring Configuration file consolidation configuration --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-service.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:config/log4j.properties</param-value> <!-- <param-value>/WEB-INF/log4j.xml</param-value> --> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Character Coding Filter --> <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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- springmvc To configure --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.action</url-pattern> <url-pattern>*.js</url-pattern> <url-pattern>*.css</url-pattern> <url-pattern>/css/**"</url-pattern> <url-pattern>/images/**</url-pattern> <url-pattern>/js/**</url-pattern> </servlet-mapping> <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> </web-app>
UserController.java
package com.ssm.manager.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.ssm.manager.pojo.User; import com.ssm.manager.service.UserService; @Controller public class UserController { @Autowired private UserService userService; @RequestMapping("getUsers") @ResponseBody public Object findUsers() { List<User> list = userService.getUsers(); return list; } @RequestMapping("xxxTest") public ModelAndView getTestHtml() { System.out.println("======================================="); return new ModelAndView("test.html"); } }
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>ssm-manager-controller</artifactId> <packaging>war</packaging> <dependencies> <dependency> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager-service</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- Introduce json Pack, Prevent Newspaper com/fasterxml/jackson/core/JsonProcessingException error --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> </dependency> <!-- Introduce json package --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> </dependency> <!-- Introduce json package --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> </dependency> <!-- Introduce json package --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> </dependency> <!-- Introduce json package --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> </dependencies> </project>
5.2 All configuration files in ssm-manager-mapper project
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>ssm-manager-mapper</artifactId> <!-- Dependency management --> <dependencies> <dependency> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager-pojo</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- Connection pool --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!-- Connection pool --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> </dependencies> <!-- If this node is not added mybatis Of mapper.xml Documents are missing. --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>
UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.ssm.manager.mapper.UserMapper"> <resultMap id="UserMapper" type="com.ssm.manager.pojo.User"> <id property="id" column="id" /> <result property="userName" column="userName" /> <result property="password" column="password" /> </resultMap> <select id="getUsers" resultMap="UserMapper"> select id,userName,password from t_user </select> <insert id="xxxUsers" parameterType="int"> INSERT INTO t_user (id,userName,password) VALUES (3,'lisi','123456'); </insert> </mapper>
UserMapper.java
/** * @Title: UserMapper.java * @Package com.ssm.manager.mapper * @Description: TODO(Describe what the document does in one sentence. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:46:07 p.m. * @version V1.0 * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ package com.ssm.manager.mapper; import java.util.List; import com.ssm.manager.pojo.User; /** * @ClassName: UserMapper * @Description: TODO(Here is a sentence describing the function of this class. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:46:07 p.m. * * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ public interface UserMapper { public List<User> getUsers(); }
5.3 Configuration of all ssm-manager-pojo files
User.java
/** * @Title: User.java * @Package com.ssm.manager.pojo * @Description: TODO(Describe what the document does in one sentence. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:43:35 p.m. * @version V1.0 * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ package com.ssm.manager.pojo; /** * @ClassName: User * @Description: TODO(Here is a sentence describing the function of this class. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:43:35 p.m. * * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ public class User { private int id; private String userName; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "User [id=" + id + ", userName=" + userName + ", password=" + password + "]"; } }
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>ssm-manager-pojo</artifactId> </project>
5.4 Configuration information for all files of ssm-manager-service
UserService.java
package com.ssm.manager.service; import java.util.List; import com.ssm.manager.pojo.User; /** * @Title: UserService.java * @Package * @Description: TODO(Describe what the document does in one sentence. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:49:28 p.m. * @version V1.0 * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ /** * @ClassName: UserService * @Description: TODO(Here is a sentence describing the function of this class. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:49:28 p.m. * * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ public interface UserService { public List<User> getUsers(); }
UserServiceImpl.java
/** * @Title: UserServiceImpl.java * @Package com.ssm.manager.service * @Description: TODO(Describe what the document does in one sentence. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:51:52 p.m. * @version V1.0 * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ package com.ssm.manager.service; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ssm.manager.mapper.UserMapper; import com.ssm.manager.pojo.User; /** * @ClassName: UserServiceImpl * @Description: TODO(Here is a sentence describing the function of this class. * @author Tiandi Ke * @date 2017 October 11, 2001, 4:51:52 p.m. * * @Copyright: 2017 www.tydic.com Inc. All rights reserved. * Note: This content is limited to the internal circulation of Shenzhen Tianyuan Dike Information Technology Co., Ltd. It is forbidden to leak and be used for other commercial purposes. */ @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; public List<User> getUsers() { return userMapper.getUsers(); } }
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>ssm-manager-service</artifactId> <!-- Dependency management --> <dependencies> <dependency> <groupId>com.ssm.manager</groupId> <artifactId>ssm-manager-mapper</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> </dependencies> </project>
5.5 ssm-manager-commons all file configuration information
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.ssm.parent</groupId> <artifactId>ssm-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.ssm.commons</groupId> <artifactId>ssm-commons</artifactId> <version>0.0.1-SNAPSHOT</version> </project>
5.6 Configuration information for all ssm-parent files
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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ssm.parent</groupId> <artifactId>ssm-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.7</java.version> <junit.version>4.12</junit.version> <spring.version>4.1.3.RELEASE</spring.version> <mybatis.version>3.2.8</mybatis.version> <mybatis.spring.version>1.2.2</mybatis.spring.version> <mysql.version>5.1.32</mysql.version> <slf4j.version>1.6.4</slf4j.version> <log4j.version>1.2.17</log4j.version> <jackson.version>2.4.2</jackson.version> <druid.version>1.0.9</druid.version> <jstl.version>1.2</jstl.version> <servlet-api.version>2.5</servlet-api.version> <jsp-api.version>2.0</jsp-api.version> <commons-lang3.version>3.3.2</commons-lang3.version> <commons-io.version>1.3.2</commons-io.version> <jedis.version>2.7.2</jedis.version> </properties> <dependencyManagement> <dependencies> <!-- Apache Tool components --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <!-- Jackson Json Processing Toolkit --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> <!-- unit testing --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <!-- Log processing --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- Connection pool --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</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-webmvc</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-aspects</artifactId> <version>${spring.version}</version> </dependency> <!-- JSP Relevant --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servlet-api.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-api.version}</version> <scope>provided</scope> </dependency> <!-- Redis Client --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>${jedis.version}</version> </dependency> <!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency> <!-- https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-core-asl --> <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-core-asl</artifactId> <version>1.9.13</version> </dependency> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.9.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.0</version> </dependency> </dependencies> </dependencyManagement> <build> <finalName>${project.artifactId}</finalName> <plugins> <!-- Resource File Copy Plug-in --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- java Compiler plug-in --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.2</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <!-- To configure Tomcat Plug-in unit --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> </plugin> </plugins> </pluginManagement> </build> </project>
All configuration file information is configured:
- summary
In this chapter, we explain how to configure various project pom files, spring transactions, spring aop, mybatis and other configurations in SSM projects.
Code path (to be determined):
mysql create statement:
/* Navicat MySQL Data Transfer Source Server : GX Source Server Version : 50636 Source Host : 127.0.0.1:3306 Source Database : ussm Target Server Type : MYSQL Target Server Version : 50636 File Encoding : 65001 Date: 2017-10-11 21:10:51 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for t_user -- ---------------------------- DROP TABLE IF EXISTS `t_user`; CREATE TABLE `t_user` ( `id` int(32) NOT NULL, `userName` varchar(255) DEFAULT NULL, `password` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- ---------------------------- -- Records of t_user -- ---------------------------- INSERT INTO `t_user` VALUES ('1', 'liuren', '123456'); INSERT INTO `t_user` VALUES ('2', 'lisi', '123456'); INSERT INTO `t_user` VALUES ('3', 'lisi', '123456');
3. SSM Project-redis Caching Strategy and Configuration Implementation
IV. SSM Project - Implementation of Springmvc Configuration
From: https://www.cnblogs.com/lr393993507/p/7652821.html