当前位置:网站首页>SSM整-整合配置
SSM整-整合配置
2022-07-26 17:39:00 【江湖大侠叶开花】
SSM整合流程
- 创建工程.
- SSM整合
- Spring
- ■SpringConfig
- MyBatis
- MybatisConfig
- JdbcConfig
- jdbc. properties
- SpringMVC
- ServletConfig
- SpringMvcConfig
- Spring
- 功能模块
- 表与实体类
- dao (接口+自动代理)
- service (接口+实现类)
- 业务层接口测试 (整合JUnit )
- controller
- 表现层接口测试( ApiFox)
- 表现层接口测试( ApiFox)
1、创建工程

2、添加依赖
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- springmvc-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>3、SSM整合
创建SpringConfig
@Configuration
@ComponentScan({"com.hyk.service"})
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MyBatisConfig.class})
//开启事务
@EnableTransactionManagement
public class SpringConfig {
}创建MyBatisConfig
public class MyBatisConfig {
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource){
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//设置类型别名的包
sqlSessionFactoryBean.setTypeAliasesPackage("com.hyk.domain");
//使用装配注入datasource
sqlSessionFactoryBean.setDataSource(dataSource);
return sqlSessionFactoryBean;
}
@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer msc = new MapperScannerConfigurer();
//设置映射的包
msc.setBasePackage("com.hyk.dao");
return msc;
}
}创建JdbcConfig
public class JdbcConfig {
@Value("${jdbc.driver}")
private String driver;
@Value("${jdbc.url}")
private String url;
@Value("${jdbc.username}")
private String username;
@Value("${jdbc.password}")
private String password;
@Bean
public DataSource dataSource(){
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName(driver);
dataSource.setUrl(url);
dataSource.setUsername(username);
dataSource.setPassword(password);
return dataSource;
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource){
DataSourceTransactionManager ds = new DataSourceTransactionManager();
ds.setDataSource(dataSource);
return ds;
}
}创建jdbc.porperties
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/restaruant?characterEncoding=utf8&serverTimezone=Asia/Shanghai
jdbc.username=root
jdbc.password=123456创建SpringMvcConfig
@Configuration
@ComponentScan("com.hyk.controller")
@EnableWebMvc
public class SpringMvcConfig {
}创建ServletConfig
public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{SpringConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[]{SpringMvcConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
//乱码处理
@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
return new Filter[]{filter};
}
}边栏推荐
- Visual VM 定位OOM,FullGC使用方法
- 14.梯度检测、随机初始化、神经网络总结
- Sudden! Arm stops cooperating with Huawei! How big is the impact on Huawei?
- Efficiency increased by 98%! AI weapon behind operation and maintenance inspection of high altitude photovoltaic power station
- PyQt5快速开发与实战 3.5 菜单栏与工具栏
- 链表-合并两个排序的列表
- [brother hero July training] day 25: tree array
- Ren Zhengfei revealed for the first time: the story behind Huawei's nearly $10billion "sale" to Motorola!
- NFT数字藏品开发:数字藏品助力企业发展
- Baidu PaddlePaddle easydl x wesken: see how to install the "eye of AI" in bearing quality inspection
猜你喜欢

The third day of SSM practice_ Paging assistant_ Security framework

Download and configuration of irrklang audio library

During the oppo interview, 16 questions were thrown over. I was stupid

剑指offer 连续子数组的最大和(二)

Maximum sum of continuous subarray of sword finger offer (2)

Duplicate gallerycms character length limit short domain name bypass

还在用Xshell?推荐这个更现代的终端连接工具
![[a little knowledge] thread pool](/img/47/7296e47b53e728d2d3b9db198243f4.png)
[a little knowledge] thread pool

Hello World

How about the employment prospects of Russian translation? How to do a good job of Russian translation
随机推荐
Arm China responded to the "disconnection of Huawei supply" incident! Ren Zhengfei said "no impact"!
俄语翻译的就业前景怎样 如何做好俄语翻译工作
MySQL练习题初级45题(统一表)
《圆圈正义》的信念
剑指offer 正则表达式匹配
14.梯度检测、随机初始化、神经网络总结
Ministry of Finance: IC design enterprises and software enterprises will be exempted from corporate income tax this year and next!
Redis core principles
Distributed link tracking Jaeger's use in golang
Oracle第一天(开发常用的知识点再回顾整理下)
成为测试/开发程序员,小张:现实就来了个下马威......
被控专利授权费过高!美法院判决高通违反反垄断法:高通股价大跌10.86%!
The step jumping expansion problem of sword finger offer
文件上传下载测试点
Data warehouse: fact table of detailed dimensional modeling
链表-两个链表的第一个公共结点
offer-集合(1)
分布式链路追踪Jaeger在Golang中的使用
贪心——455. 分发饼干
Real passwords do not match during synchronization