当前位置:网站首页>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. !!!!!!!!!!!!!!
边栏推荐
- CMD window under Windows connects to MySQL and operates the table
- Fantom (FTM) 价格将在未来几天飙升 20%
- 焕然一新,swagger UI 主题更改
- 如何零代码制作深度学习的趣味app(适合新手)
- 北京宝德&TaoCloud共建信创之路
- 学习、研究编程之道
- The difference between link and @import importing external styles
- 剑指核心-TaoCloud全闪SDS助力构建高性能云服务
- How can Plato obtain premium income through elephant swap in a bear market?
- Elastic box flex
猜你喜欢

Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round

剑指核心-TaoCloud全闪SDS助力构建高性能云服务

Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围

手撕ORM 框架(泛型+注解+反射)

ssm整合

中海油集团,桌面云&网盘存储系统应用案例

华为2020校招笔试编程题 看这篇就够了(上)

与多家机构战略合作,背后彰显PlatoFarm元宇宙龙头的实力

The completely decentralized programming mode does not need servers or IP, just like a aimless network extending everywhere

Laravel Swagger添加访问密码
随机推荐
学习、研究编程之道
完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
与张小姐的春夏秋冬(5)
重庆大道云行作为软件产业代表受邀参加渝中区重点项目签约仪式
win10+opencv3.2+vs2015配置
Plato farm is expected to further expand its ecosystem through elephant swap
Power BI Report Server 自定义身份验证
如何在加密市场熊市中生存?
Reporting Service 2016 自定义身份验证
北京宝德&TaoCloud共建信创之路
Breaking through the hardware bottleneck (I): the development of Intel Architecture and bottleneck mining
day02 作业之文件权限
Research and implementation of flash loan DAPP
突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘
Synchronous development with open source projects & codereview & pull request & Fork how to pull the original warehouse
MOVE PROTOCOL全球健康宣言,将健康运动进行到底
Gluster cluster management analysis
与张小姐的春夏秋冬(3)
Windows下cmd窗口连接mysql并操作表
XDFS&空天院HPC集群典型案例