SSM整合
在b站黑马学习的SMM框架,老师很有耐心演示的SMM项目整合,一下是使用一个BOOK类,在MYSQL创建一个tbl_book表,用spring整合ssm写了增删改查的基本功能,由于我是在typora做的笔记所以在csdn上可能有些乱码
源码以及markdown笔记链接:https://kdocs.cn/l/cjaliZyy4Yuo
整合流程
Spring整合SSM
这是整体代码结构
-
配置
-
SpringConfig
-
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@ComponentScan({“com.itheima.service”})
@PropertySource(“classpath:jdbc.properties”) //导入jdbc配置
@Import({JdbcConfig.class,MyBatisConfig.class}) //导入jdbc和mybatis的配置
@EnableTransactionManagement //1.开启事务管理
public class SpringConfig {
}
```
-
SpringMVC
-
WEB配置类
-
```java
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import javax.servlet.Filter;
public class ServletWebConfig 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() {
<