当前位置:网站首页>SSM integration
SSM integration
2022-07-29 05:53:00 【Don't want bald Xiao Yang】
Catalog
1.ssm The principle of integration
2. Create a MAVEN-web engineering
4. To write spring The configuration file
6.generator The generated code
1.ssm The principle of integration

2. Create a MAVEN-web engineering

Replace web.xml Documents in
<?xml version="1.0" encoding="UTF-8"?>
<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_4_0.xsd"
version="4.0">
</web-app> 3. Add dependency
<dependencies>
<!--spring-webmvc-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.15.RELEASE</version>
</dependency>
<!--mybatis rely on -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<!--mybatis and spring Integration dependency -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!--mysql drive -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<!--druid Connection pool dependency -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.1</version>
</dependency>
<!--lombok rely on -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<!--jackson java Object to json object @ResponseBody-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
</dependency>
<!--servlet-api rely on -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>4. To write spring 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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Package scanning -->
<context:component-scan base-package="com.ykq"/>
<!-- Open the annotation -->
<mvc:annotation-driven/>
<!-- Release of static resources -->
<mvc:default-servlet-handler/>
<!--spring Configuration of -->
<!-- Data source configuration -->
<bean id="ds" class="com.alibaba.druid.pool.DruidDataSource">
<!-- Driver name -->
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<!-- Number of initialized connection pools -->
<property name="initialSize" value="5"/>
<!-- At least the number -->
<property name="minIdle" value="5"/>
<!-- Maximum number -->
<property name="maxActive" value="10"/>
<!-- The maximum waiting time unit is milliseconds -->
<property name="maxWait" value="3000"/>
</bean>
<!--sqlSessionFactory Integrate mybatis-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds"/>
<!-- Set up mybatis Path to map file -->
<property name="mapperLocations" value="classpath:mapper/*.xml"/>
</bean>
<!-- by dao Interface to generate proxy implementation classes -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- by com.ykq.dao The interface under the package generates a proxy implementation class -->
<property name="basePackage" value="com.ykq.dao"/>
</bean>
</beans>5. To configure web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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_4_0.xsd"
version="4.0">
<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:springmvc.xml</param-value>
</init-param>
<!-- When tomcat Create at startup DipatcherServlet Default when accessing controller Path creation -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>To configure tomcat And start the
common problem :

terms of settlement : Lack of dependence
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.15.RELEASE</version>
</dependency>6.generator The generated code
(1) rely on
<!--generator-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.4.0</version>
</dependency>(2) The configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- Find you. mysql drive jar The location of -->
<classPathEntry location="D:\repMaven\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- Suppress comments -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- Configuration information of data source -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai"
userId="root"
password="root">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--java Configuration of entity class -->
<javaModelGenerator targetPackage="com.ykq.entity" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- Mapping file configuration -->
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--dao Configuration of data access layer -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.ykq.dao" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- Mapping relationship between database tables and entities
schema: Database name
tableName: Table name
domainObjectName: Entity class name
enableUpdateByExample: Whether to generate complex modification operations
-->
<table schema="mybatis" tableName="tbl_user" domainObjectName="Users"
enableUpdateByExample="false" enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false">
</table>
</context>
</generatorConfiguration>(3) test
public class TestGeneratory {
public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("generator.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
}7. add to sql journal
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>log4j.properties----- Content
log4j.rootLogger=DEBUG, Console
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUGThank you for watching. !!!!!!!!!!!!!!
边栏推荐
- Plato farm is expected to further expand its ecosystem through elephant swap
- How to make interesting apps for deep learning with zero code (suitable for novices)
- Windows下cmd窗口连接mysql并操作表
- iSCSI vs iSER vs NVMe-TCP vs NVMe-RDMA
- XDFS&空天院HPC集群典型案例
- 焕然一新,swagger UI 主题更改
- 识变!应变!求变!
- "Shandong University mobile Internet development technology teaching website construction" project training log I
- DAY4:SQL Sever 简单使用
- Markdown语法
猜你喜欢

极致通缩和永动机模型,将推动 PlatoFarm 爆发

Gluster集群管理小分析

D3.JS 纵向关系图(加箭头,连接线文字描述)

Strategic cooperation with many institutions shows the strength of the leading company of platofarm yuancosmos

Xsan is highly available - xdfs and San are integrated with new vitality

Detailed steps of JDBC connection to database

day02 作业之文件权限

突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘

Sliding switch of tab of uniapp component

php写一个购买全网最低价的纸尿裤
随机推荐
Dao race track is booming. What are the advantages of m-dao?
xSAN高可用—XDFS与SAN融合焕发新生命力
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
马斯克推崇的柏拉图式元宇宙,PlatoFarm早已验证出答案
7 月 28 日 ENS/USD 价值预测:ENS 吸引巨额利润
Under the bear market of encrypted assets, platofarm's strategy can still obtain stable income
rsync+inotyfy实现数据单项监控实时同步
D3.JS 纵向关系图(加箭头,连接线文字描述)
xtrabackup 的使用
全闪分布式,如何深度性能POC?
Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
如何 Pr 一个开源composer项目
DeFi 2.0的LaaS协议,重振DeFi赛道发展的关键
Some opportunities for young people in rural brand building
SQL修复重复数据
钉钉告警脚本
与张小姐的春夏秋冬(2)
XDFS&空天院HPC集群典型案例
How to survive in the bear market of encryption market?
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值