当前位置:网站首页>Basic construction of SSM framework
Basic construction of SSM framework
2022-06-26 06:03:00 【Source code Xiao Liu】
Preface : Whether working or studying , We often need to build our own project framework , College students or beginners often encounter unknown mistakes , Waste time on this , Now let's talk about SSM Framework construction and basic use , Whether to use IDEA still Eclipse , maven Project built ssm Same frame structure , The following example uses IDEA Create .
1.IEAD Use Maven Create project
As shown in the figure below , According to the prompt next

reminder , Please make sure your computer is installed maven And configured environment variables , It is best to configure Alibaba image acceleration .

The project directory is as follows :

We need to add some configuration ,ssm The basic configuration of the is as follows :
2. To configure SSM frame
2.1 pom.xml Add required jar package
<!--web mvc what is needed jar-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<!--jackson-->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</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.8</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.8</version>
</dependency>
<!--
spring-mvc
-->
<!--
database spring And mybatis Integration required jar
-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.2</version>
</dependency>
<!--
database spring And mybatis Integration required jar
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>2.0.2</version>
</dependency>
<!-- Spring AOP section modular -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.2</version>
</dependency>
<!--
test
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.14.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>2.2 web.xml
<!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>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>DispatcherServlet</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>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
2.3 spring-mybatis-mysql.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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Read multiple configuration files into the container , hand Spring management -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- Multiple addressing modes are supported here :classpath and file -->
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
<property name="driverClassName" value="${driverClassName}"/>
<property name="jdbcUrl" value="${jdbcUrl}"/>
<!-- When connecting to a read-only database, it is configured as true, Keep it safe -->
<property name="readOnly" value="false" />
<!-- The maximum length of time to wait for the connection pool to allocate the connection ( millisecond ), Connections that have not been available for more than this period of time occur SQLException, default :30 second -->
<property name="connectionTimeout" value="30000" />
<!-- A connection idle The maximum duration of a state ( millisecond ), Timeout is released (retired), default :10 minute -->
<property name="idleTimeout" value="600000" />
<!-- A connected life span ( millisecond ), Time out and not used is released (retired), default :30 minute , It is recommended to set the timeout less than the database 30 second , Reference resources MySQL
wait_timeout Parameters (show variables like '%timeout%';) -->
<property name="maxLifetime" value="1800000" />
<!-- The maximum number of connections allowed in the connection pool . The default value :10; Recommended formula :((core_count * 2) + effective_spindle_count) -->
<property name="maximumPoolSize" value="60" />
<property name="minimumIdle" value="10" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath:mapper/*.xml" />
<!-- Note other configurations -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!-- Use the following method to configure parameters , Configure one... Line by line -->
<value>
rowBoundsWithCount=true
PageRowBounds=true
offsetAsPageNum=true
pageSizeZero=true
reasonable=true
</value>
</property>
</bean>
</array>
</property>
<property name="configLocation" value="classpath:mybatis_configer.xml"></property><!-- To configure mybatis Logging of -->
</bean>
<!-- Scan dependency injection correlation interface -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
</beans>2.4 spring-mvc.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"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
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.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<!-- Enable spring mvc annotation -->
<import resource="spring-mybatis-mysql.xml"/>
<context:component-scan base-package="com"/>
<!-- Open annotation mode -->
<context:annotation-config />
<mvc:annotation-driven/>
<mvc:default-servlet-handler/> <!-- Access settings for static resources -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="suffix" value=".jsp"/>
</bean>
</beans>The directory structure is as follows :

Control layer interface :
@RequestMapping(value = "/getSqlList")
@ResponseBody
public void faff(){
System.out.println("----------------------mysql---------------------------");
List<Map<String, Object>> maps = userMapper.getAll2222();
maps.forEach(t-> System.out.println(t));
}Page effects will not be repeated , The effect of data request is as follows :

If there is any confusion , Please add java Like to communicate with others :852665736; The group is full of hospitable friends , Let's make progress together .
Free sharing of source code, technology and interview documents , For more excellent and exquisite source code technology stack sharing, please follow wechat official account :gh_817962068649
边栏推荐
- cross entropy loss = log softmax + nll loss
- Record how to modify the control across threads
- Vs2022 offline installation package download and activation
- Pytorch (network model)
- Day2- syntax basis and variables
- Day3 - variables and operators
- SQL Server view
- numpy.frombuffer()
- RIA ideas
- 操作符的优先级、结合性、是否控制求值顺序【详解】
猜你喜欢

How to associate wechat applet QR code to realize two code aggregation

Household accounting procedures (the second edition includes a cycle)

421-二叉树(226. 翻转二叉树、101. 对称二叉树、104.二叉树的最大深度、222.完全二叉树的节点个数)

MySQL database-01 database overview

MySQL-07

MySQL-09

原型模式,咩咩乱叫

kolla-ansible部署openstack yoga版本
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast

家庭记账程序(第一版)
随机推荐
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
Consul service registration and discovery
SQL server functions
Unicloud cloud development obtains applet user openid
Customize WebService as a proxy to solve the problem of Silverlight calling WebService across domains
MySQL-06
Hot! 11 popular open source Devops tools in 2021!
Day3 - variables and operators
在web页面播放rtsp流视频(webrtc)
Younger sister Juan takes you to learn JDBC -- two days' Sprint Day2
Thread status and stop
MySQL-08
On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back
Sql语法中循环的使用
Redis underlying data structure
cross entropy loss = log softmax + nll loss
Keepalived to achieve high service availability
Detailed explanation of serial port communication principle 232, 422, 485
How to associate wechat applet QR code to realize two code aggregation
numpy. tile()