√ SSM
文章目录
- 0. 关系图
- 1. 【pom.xml】
- 2. 【xxxMapper.xml】
- 3. 【mybatis-config.xml】
- 4. 【applicationContext.xml】
- 5. 【database.properties】
- 6. 【spring-dao.xml】
- 7. 【spring-service.xml】
- 8. 【spring-mvc.xml】
- 9. 【web.xml】
0. 关系图
1. 【pom.xml】
- 导入依赖:Junit、数据库驱动、数据库连接池、Servlet-JSP、MyBatis、Spring、Lombok
- 导出静态资源
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"xmlns:xsi=""xsi:schemaLocation=".0.0.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.acai</groupId><artifactId>SSM</artifactId><version>1.0-SNAPSHOT</version><properties><mavenpiler.source>8</mavenpiler.source><mavenpiler.target>8</mavenpiler.target></properties><!--1.导入依赖--><dependencies><!--(1)Junit--><!-- --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><!--(2)数据库驱动--><!-- --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!--(3)数据库连接池--><!-- .alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.6</version></dependency><!--(4)Servlet-JSP--><!-- .servlet/servlet-api --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version></dependency><!-- .servlet.jsp/jsp-api --><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version></dependency><!-- .servlet/jstl --><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!--(5)MyBatis--><!-- .mybatis/mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.2</version></dependency><!-- .mybatis/mybatis-spring --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.2</version></dependency><!--(6)Spring--><!-- .springframework/spring-webmvc --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.1.9.RELEASE</version></dependency><!-- .springframework/spring-jdbc --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.9.RELEASE</version></dependency><!-- .aspectj/aspectjweaver --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.3</version></dependency><!--(7)Lombok--><!-- .projectlombok/lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></dependency></dependencies><!--2.导出静态资源--><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>
</project>
2. 【xxxMapper.xml】
- 绑定实体类的xxxMapper接口
- 表字段映射到实体类属性
- SQL语句:增、删、改、查
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<!--1.绑定实体类的xxxMapper接口-->
<mapper namespace="com.acai.dao.【xxxMapper】"><!--2.表字段映射到实体类属性--><resultMap id="【xxxMap】" type="【实体类】"><id column="【表字段】" property="【实体类属性】"/></resultMap><!--3.SQL语句--><!--增--><insert id="【方法名】" parameterType="【参数类型】"></insert><!--删--><delete id="【方法名】" parameterType="【参数类型】"></delete><!--改--><update id="【方法名】" parameterType="【参数类型】"></update><!--查--><select id="【方法名】" resultMap="【xxxMap】"></select>
</mapper>
3. 【mybatis-config.xml】
- 配置日志功能
- 给实体类添加别名
- 绑定实体类的xxxMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis//DTD Config 3.0//EN"".dtd">
<configuration><!--1.配置日志功能--><settings><setting name="logImpl" value="STDOUT_LOGGING"/></settings><!--2.给实体类添加别名--><typeAliases><package name="com.acai.pojo"/></typeAliases><!--3.绑定实体类的xxxMapper.xml--><mappers><mapper resource="com/acai/dao/【xxxMapper.xml】"/></mappers>
</configuration>
4. 【applicationContext.xml】
- 关联dao、service、mvc配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd"><!--1.关联dao、service、mvc配置文件--><import resource="classpath:spring-dao.xml"/><import resource="classpath:spring-service.xml"/><import resource="classpath:spring-mvc.xml"/>
</beans>
5. 【database.properties】
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/【数据库名】?useSSL=false&useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
6. 【spring-dao.xml】
- 关联数据库配置文件
- 配置数据库连接池
- 配置sqlSessionFactory:注入数据源、绑定mybatis配置文件
- 配置dao接口扫描包,动态实现将dao接口注入到spring容器中:注入sqlSessionFactory、配置要扫描的包
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:context=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/context/spring-context.xsd"><!--1.关联数据库配置文件--><context:property-placeholder location="classpath:database.properties"/><!--2.配置数据库连接池--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!--3.配置sqlSessionFactory--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--注入数据源--><property name="dataSource" ref="dataSource"/><!--绑定mybatis配置文件--><property name="configLocation" value="classpath:mybatis-config.xml"/></bean><!--4.配置dao接口扫描包,动态实现将dao接口注入到spring容器中--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!--注入sqlSessionFactory--><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!--配置要扫描的包--><property name="basePackage" value="com.acai.dao"/></bean>
</beans>
7. 【spring-service.xml】
- 扫描service包
- 将所有xxxServiceImpl注入到spring容器中
- 声明式事务配置:注入数据源
- 配置事务通知
- 配置事务切入
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:context=""xmlns:tx=""xmlns:aop=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/context/spring-context.xsd://www.springframework/schema/tx/spring-tx.xsd://www.springframework/schema/aop/spring-aop.xsd"><!--1.扫描service包--><context:component-scan base-package="com.acai.service"/><!--2.将所有xxxServiceImpl注入到spring容器中--><bean id="【xxxService】" class="com.acai.service.【xxxServiceImpl】"><property name="【xxxMapper】" ref="【xxxMapper】"/></bean><!--3.声明式事务配置--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!--注入数据源--><property name="dataSource" ref="dataSource"/></bean><!--4.配置事务通知--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="*" propagation="REQUIRED"/></tx:attributes></tx:advice><!--5.配置事务切入--><aop:config><aop:pointcut id="txPointCut" expression="execution(* com.acai.dao.*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/></aop:config>
</beans>
8. 【spring-mvc.xml】
- 注解驱动
- 静态资源过滤
- 扫描controller包
- 视图解析器:配置前缀、配置后缀
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:mvc=""xmlns:context=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/mvc/spring-mvc.xsd://www.springframework/schema/context/spring-context.xsd"><!--1.注解驱动--><mvc:annotation-driven/><!--2.静态资源过滤--><mvc:default-servlet-handler/><!--3.扫描controller包--><context:component-scan base-package="com.acai.controller"/><!--4.视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!--配置前缀--><property name="prefix" value="/WEB-INF/page/"/><!--配置后缀--><property name="suffix" value=".jsp"/></bean>
</beans>
9. 【web.xml】
- 配置DispatcherServlet:绑定applicationContext.xml
- 配置乱码过滤
- 配置session超时时间
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""xmlns:xsi=""xsi:schemaLocation="://xmlns.jcp/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--1.配置DispatcherServlet--><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--绑定applicationContext.xml--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!--2.配置乱码过滤--><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--3.配置session超时时间--><session-config><session-timeout>15</session-timeout></session-config>
</web-app>
√ SSM
文章目录
- 0. 关系图
- 1. 【pom.xml】
- 2. 【xxxMapper.xml】
- 3. 【mybatis-config.xml】
- 4. 【applicationContext.xml】
- 5. 【database.properties】
- 6. 【spring-dao.xml】
- 7. 【spring-service.xml】
- 8. 【spring-mvc.xml】
- 9. 【web.xml】
0. 关系图
1. 【pom.xml】
- 导入依赖:Junit、数据库驱动、数据库连接池、Servlet-JSP、MyBatis、Spring、Lombok
- 导出静态资源
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=".0.0"xmlns:xsi=""xsi:schemaLocation=".0.0.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.acai</groupId><artifactId>SSM</artifactId><version>1.0-SNAPSHOT</version><properties><mavenpiler.source>8</mavenpiler.source><mavenpiler.target>8</mavenpiler.target></properties><!--1.导入依赖--><dependencies><!--(1)Junit--><!-- --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency><!--(2)数据库驱动--><!-- --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.47</version></dependency><!--(3)数据库连接池--><!-- .alibaba/druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.6</version></dependency><!--(4)Servlet-JSP--><!-- .servlet/servlet-api --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.5</version></dependency><!-- .servlet.jsp/jsp-api --><dependency><groupId>javax.servlet.jsp</groupId><artifactId>jsp-api</artifactId><version>2.2</version></dependency><!-- .servlet/jstl --><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!--(5)MyBatis--><!-- .mybatis/mybatis --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.2</version></dependency><!-- .mybatis/mybatis-spring --><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.2</version></dependency><!--(6)Spring--><!-- .springframework/spring-webmvc --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.1.9.RELEASE</version></dependency><!-- .springframework/spring-jdbc --><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.1.9.RELEASE</version></dependency><!-- .aspectj/aspectjweaver --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.3</version></dependency><!--(7)Lombok--><!-- .projectlombok/lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.20</version></dependency></dependencies><!--2.导出静态资源--><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>
</project>
2. 【xxxMapper.xml】
- 绑定实体类的xxxMapper接口
- 表字段映射到实体类属性
- SQL语句:增、删、改、查
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis//DTD Mapper 3.0//EN"".dtd">
<!--1.绑定实体类的xxxMapper接口-->
<mapper namespace="com.acai.dao.【xxxMapper】"><!--2.表字段映射到实体类属性--><resultMap id="【xxxMap】" type="【实体类】"><id column="【表字段】" property="【实体类属性】"/></resultMap><!--3.SQL语句--><!--增--><insert id="【方法名】" parameterType="【参数类型】"></insert><!--删--><delete id="【方法名】" parameterType="【参数类型】"></delete><!--改--><update id="【方法名】" parameterType="【参数类型】"></update><!--查--><select id="【方法名】" resultMap="【xxxMap】"></select>
</mapper>
3. 【mybatis-config.xml】
- 配置日志功能
- 给实体类添加别名
- 绑定实体类的xxxMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis//DTD Config 3.0//EN"".dtd">
<configuration><!--1.配置日志功能--><settings><setting name="logImpl" value="STDOUT_LOGGING"/></settings><!--2.给实体类添加别名--><typeAliases><package name="com.acai.pojo"/></typeAliases><!--3.绑定实体类的xxxMapper.xml--><mappers><mapper resource="com/acai/dao/【xxxMapper.xml】"/></mappers>
</configuration>
4. 【applicationContext.xml】
- 关联dao、service、mvc配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd"><!--1.关联dao、service、mvc配置文件--><import resource="classpath:spring-dao.xml"/><import resource="classpath:spring-service.xml"/><import resource="classpath:spring-mvc.xml"/>
</beans>
5. 【database.properties】
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/【数据库名】?useSSL=false&useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123456
6. 【spring-dao.xml】
- 关联数据库配置文件
- 配置数据库连接池
- 配置sqlSessionFactory:注入数据源、绑定mybatis配置文件
- 配置dao接口扫描包,动态实现将dao接口注入到spring容器中:注入sqlSessionFactory、配置要扫描的包
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:context=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/context/spring-context.xsd"><!--1.关联数据库配置文件--><context:property-placeholder location="classpath:database.properties"/><!--2.配置数据库连接池--><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!--3.配置sqlSessionFactory--><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><!--注入数据源--><property name="dataSource" ref="dataSource"/><!--绑定mybatis配置文件--><property name="configLocation" value="classpath:mybatis-config.xml"/></bean><!--4.配置dao接口扫描包,动态实现将dao接口注入到spring容器中--><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!--注入sqlSessionFactory--><property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/><!--配置要扫描的包--><property name="basePackage" value="com.acai.dao"/></bean>
</beans>
7. 【spring-service.xml】
- 扫描service包
- 将所有xxxServiceImpl注入到spring容器中
- 声明式事务配置:注入数据源
- 配置事务通知
- 配置事务切入
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:context=""xmlns:tx=""xmlns:aop=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/context/spring-context.xsd://www.springframework/schema/tx/spring-tx.xsd://www.springframework/schema/aop/spring-aop.xsd"><!--1.扫描service包--><context:component-scan base-package="com.acai.service"/><!--2.将所有xxxServiceImpl注入到spring容器中--><bean id="【xxxService】" class="com.acai.service.【xxxServiceImpl】"><property name="【xxxMapper】" ref="【xxxMapper】"/></bean><!--3.声明式事务配置--><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!--注入数据源--><property name="dataSource" ref="dataSource"/></bean><!--4.配置事务通知--><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="*" propagation="REQUIRED"/></tx:attributes></tx:advice><!--5.配置事务切入--><aop:config><aop:pointcut id="txPointCut" expression="execution(* com.acai.dao.*.*(..))"/><aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/></aop:config>
</beans>
8. 【spring-mvc.xml】
- 注解驱动
- 静态资源过滤
- 扫描controller包
- 视图解析器:配置前缀、配置后缀
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""xmlns:xsi=""xmlns:mvc=""xmlns:context=""xsi:schemaLocation="://www.springframework/schema/beans/spring-beans.xsd://www.springframework/schema/mvc/spring-mvc.xsd://www.springframework/schema/context/spring-context.xsd"><!--1.注解驱动--><mvc:annotation-driven/><!--2.静态资源过滤--><mvc:default-servlet-handler/><!--3.扫描controller包--><context:component-scan base-package="com.acai.controller"/><!--4.视图解析器--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!--配置前缀--><property name="prefix" value="/WEB-INF/page/"/><!--配置后缀--><property name="suffix" value=".jsp"/></bean>
</beans>
9. 【web.xml】
- 配置DispatcherServlet:绑定applicationContext.xml
- 配置乱码过滤
- 配置session超时时间
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=""xmlns:xsi=""xsi:schemaLocation="://xmlns.jcp/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--1.配置DispatcherServlet--><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--绑定applicationContext.xml--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><!--2.配置乱码过滤--><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>utf-8</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><!--3.配置session超时时间--><session-config><session-timeout>15</session-timeout></session-config>
</web-app>
发布评论