当前位置:网站首页>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
边栏推荐
猜你喜欢

工厂方法模式、抽象工厂模式
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast

Redis underlying data structure

Kolla ansible deploy openstack Yoga version

【C语言】深度剖析数据在内存中的存储

数据可视化实战:实验报告

Unicloud cloud development obtains applet user openid

Household accounting procedures (the second edition includes a cycle)

Tortoise and rabbit race example

小程序如何关联微信小程序二维码,实现二码聚合
随机推荐
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
冒泡排序(Bubble Sort)
Pytorch (environment, tensorboard, transforms, torchvision, dataloader)
Gram 矩阵
numpy. exp()
Mongodb——使用Mongodb对字段中字符串内容进行截取,并进行分组统计
The use of loops in SQL syntax
Selective search for object recognition paper notes [image object segmentation]
Redis multithreading and ACL
Multi thread synchronous downloading of network pictures
Customize WebService as a proxy to solve the problem of Silverlight calling WebService across domains
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
重载和重写
numpy. tile()
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
Day4 branch and loop
Posting - don't get lost in the ocean of Technology
SQL Server视图
A new journey
Cython入门