【尚筹网IDEA版】03-SSM整合测试
先前的记录:
【尚筹网IDEA版】02-数据库创建、Mybatis逆向、Spring整合Mybatis
代码下载:
git clone https://github.com/YuanbaoQiang/atcrowdfunding.git
atcrowdfunding01-admin-parent
这里需要配置的就是一个pom.xml
,在这个pom.xml中可以提前将需要涉及到的jar包进行版本约束,防止后期的因为版本不一致而导致的版本冲突。
相关链接:
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yuanbaoqiang.crowd</groupId>
<artifactId>atcrowdfunding01-admin-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>atcrowdfunding02-admin-webui</module>
<module>atcrowdfunding03-admin-component</module>
<module>atcrowdfunding04-admin-entity</module>
<module>atcrowdfunding05-common-util</module>
<module>atcrowdfunding06-common-reverse</module>
</modules>
<properties>
<!-- 声明属性,对Spring 的版本进行统一管理-->
<atyuanbaoqiang.spring.version>5.2.10.RELEASE</atyuanbaoqiang.spring.version>
<!-- 声明属性,对SpringSecurity 的版本进行统一管理-->
<atyuanbaoqiang.spring.security.version>5.4.1</atyuanbaoqiang.spring.security.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring 依赖-->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${atyuanbaoqiang.spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${atyuanbaoqiang.spring.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${atyuanbaoqiang.spring.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>
<!-- 数据库依赖-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<!-- 数据源-->
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.1</version>
</dependency>
<!-- MyBatis -->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
<!-- MyBatis 与Spring 整合-->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.5</version>
</dependency>
<!-- MyBatis 分页插件-->
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.2.0</version>
</dependency>
<!-- 日志-->
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha5</version>
<scope>test</scope>
</dependency>
<!-- 其他日志框架的中间转换包-->
<!-- https://mvnrepository.com/artifact/org.slf4j/jcl-over-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- Spring 进行JSON 数据转换依赖-->
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.0-rc1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.0-rc1</version>
</dependency>
<!-- JSTL 标签库-->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- junit 测试-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- 引入Servlet 容器中相关依赖-->
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<!-- JSP 页面使用的依赖-->
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2.1-b03</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- SpringSecurity 对Web 应用进行权限管理-->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.4.1</version>
</dependency>
<!-- SpringSecurity 配置-->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.4.1</version>
</dependency>
<!-- SpringSecurity 标签库-->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>5.4.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
atcrowdfunding02-admin-webui
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>atcrowdfunding01-admin-parent</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>atcrowdfunding02-admin-webui</artifactId>
<packaging>war</packaging>
<name>atcrowdfunding02-admin-webui Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<artifactId>atcrowdfunding03-admin-component</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- junit测试 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.10.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- 引入Servlet容器中相关依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>
<!-- JSP页面使用的依赖 -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2.1-b03</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
AdminMapper.xml
由mybatis****直接实现
jdbc.properties
jdbc.username=root
jdbc.password=qyb19970829
jdbc.url=jdbc:mysql://localhost:3306/project_crowd?serverTimezone=GMT
jdbc.driver=com.mysql.cj.jdbc.Driver
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<!-- 指定日志输出的位置-->
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- 日志输出的格式-->
<!-- 按照顺序分别是:时间、日志级别、线程名称、打印日志的类、日志主体
内容、换行-->
<pattern>[%d{HH:mm:ss.SSS}] [%-5level] [%thread] [%logger] [%msg]%n</pattern>
</encoder>
</appender>
<!-- 设置全局日志级别。日志级别按顺序分别是:DEBUG、INFO、WARN、ERROR -->
<!-- 指定任何一个日志级别都只打印当前级别和后面级别的日志。-->
<root level="DEBUG">
<!-- 指定打印日志的appender,这里通过“STDOUT”引用了前面配置的appender -->
<appender-ref ref="STDOUT" />
</root>
<!-- 根据特殊需求指定局部日志级别-->
<logger name="com.yuanbaoqiang.crowd.mapper" level="DEBUG"/>
</configuration>
mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
spring-persist-mybatis.xml
相关链接参考:
value与ref的区别:
Spring框架xml配置中属性 ref 与 value的区别
classpath:
和classpath*:
的区别:
web.xml 配置中classpath: 与classpath*:的区别
注意,如果value处,不写classpath:可能会提示找不到文件,还有由于部分配置文件在resources的子目录下,还需要考虑资源过滤问题!
找不到资源文件而导致的bean创建失败:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactoryBean’ defined in file [E:\IdeaWorkSpace\atcrowdfunding01-admin-parent\atcrowdfunding02-admin-webui\target\atcrowdfunding02-admin-webui-1.0-SNAPSHOT\WEB-INF\classes\spring-persist-mybatis.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/mybatis-config.xml]
<?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"
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">
<!-- 加载外部的配置文件-->
<!-- 加载jdbc.properties-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- 配置连接池属性 -->
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!-- 配置sqlSessionFactoryBean整合mybatis-->
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 装配数据源-->
<property name="dataSource" ref="dataSource"/>
<!-- 指定mybatis的全局配置文件位置-->
<property name="configLocation" value="classpath:mybatis-config.xml"/>
<property name="mapperLocations" value="classpath:mybatis/mapper/*Mapper.xml"/>
</bean>
<!-- 配置MapperScannerConfiguration来扫描Mapper接口所在的包-->
<bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 如果有多个数据源,需要指定sqlSessionFactory
Usually this is only needed when you have more than one datasource.
默认用value,而不是ref
This is because the scanner loads early during the start process and it is too early to build mybatis object instances.
扫描器加载在线程的早期,现在还未实例化任何的mybatis实例
-->
<!-- <property name="sqlSessionFactoryBeanName" value=""/>-->
<!-- 注入sqlSessionFactory-->
<!-- <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>-->
<property name="basePackage" value="com.yuanbaoqiang.crowd.mapper"/>
</bean>
</beans>
spring-persist-tx.xml
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
https://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 配置自动扫描的包:主要是为了把Service扫描到IOC容器中-->
<context:component-scan base-package="com.yuanbaoqiang.crowd.service"/>
<!-- 配置事务管理器-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 装配数据源-->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 配置事务切面-->
<aop:config>
<!-- <aop:pointcut id="" expression="execution(public String com.yuanbaoqiang.crowd.service.AdminService.saveAdmin(Admin))"/>-->
<!-- 考虑到后面整合SpringSecurity,避免把UserDetailsService加入到事务控制
则直接定位到Impl类,而不是接口了
-->
<aop:pointcut id="txPointcut" expression="execution(* *..*ServiceImpl.*(..))"/>
<!-- 将切入点表达式和事务通知关联起来-->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
<!-- 配置事务通知-->
<tx:advice id="txAdvice" transaction-manager="txManager">
<!-- 配置事务的属性-->
<tx:attributes>
<!-- 查询的方法:配置只读操作,让数据库知道这是一个查询操作,能够进行一定优化-->
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="count*" read-only="true"/>
<!-- 增删改方法:配置事务传播行为、回滚异常-->
<!--
propagation属性:
PROPAGATION_REQUIRED:此时如果有事务,则直接用当前事务,但是如果别人出现异常回滚,则自己也会回滚
PROPAGATION_REQUIRES_NEW:不管当前线程上有没有事务,我们都会自己开一个事务,在自己的事务中运行
-->
<!-- rollback-for属性:
默认:运行时异常回滚
建议:编译时异常和运行时异常都进行回滚
-->
<tx:method name="save*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception"/>
<tx:method name="update*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception"/>
<tx:method name="remove*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception"/>
<tx:method name="batch*" propagation="REQUIRES_NEW" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>
</beans>
spring-web-mvc.xml
<?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">
<!-- 配置自动扫描的包:扫描handler-->
<context:component-scan base-package="com.yuanbaoqiang.crowd.mvc"/>
<!-- 配置SpringMVC的注解驱动-->
<mvc:annotation-driven/>
<!-- 2. 静态资源默认servlet配置-->
<!-- <mvc:default-servlet-handler/>-->
<!-- 配置试图解析器-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
web.xml
<?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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-persist-*.xml</param-value>
</context-param>
<filter>
<filter-name>CharacterEncodingFilter</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>
<!-- 强制请求进行编码-->
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<!-- 强制响应进行编码-->
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 这个Filter执行器的操作 要在其他Filter前面-->
<!-- 原因如下:
request.setCharacterEncoding(encoding); 必须在request.getParameter()前面
reponse.setCharacterEncoding(encoding); 必须在reponse.getParameter()前面
-->
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-web-mvc.xml</param-value>
</init-param>
<!-- servlet默认生命周期中,创建都西昂是第一次接受请求的时候
而DispatcherServlet创建对象后有大量的“框架初始化”工作,不适合在第一次请求时来做
load-on-startup就是为了让Dispatcher在web应用启动的时候创建对象、初始化
-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<!-- url-pattern配置方式一:/表示拦截所有的请求-->
<!-- <url-pattern>/</url-pattern>-->
<!-- url-pattern配置方式二:配置请求扩展名-->
<!-- 优点1:xxx.css xxx.js xxx.png等静态资源-->
<!-- 优点2:实现伪静态效果,表面*问的是一个HTML文件这样的静态资源,实际上是经过java代码运算过的-->
<!-- 伪静态作用1:给黑客增加增加难度。-->
<!-- 伪静态作用2:有利于SEO的优化(让百度、谷歌这样的搜索更容易找到我们的项目)-->
<!-- 缺点:不符合restful风格-->
<url-pattern>*.html</url-pattern>
<!-- 为什么要另外配置json扩展名呢?-->
<!-- 如果一个Ajax请求扩展名为html,但是实际服务器给浏览器返回的是json数据,二者就不匹配了-->
<url-pattern>*.json</url-pattern>
</servlet-mapping>
</web-app>
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/test/ssm.html">测试ssm整合环境</a>
</body>
</html>
target.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>success</h1>
${requestScope.adminList}
</body>
</html>
atcrowdfunding03-admin-component
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>atcrowdfunding01-admin-parent</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>atcrowdfunding03-admin-component</artifactId>
<dependencies>
<!-- 添加module依赖-->
<dependency>
<artifactId>atcrowdfunding04-admin-entity</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<artifactId>atcrowdfunding05-common-util</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--//-->
<!-- Spring依赖 -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
</dependency>
<!-- 数据库依赖 -->
<!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 数据库连接池 -->
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<!-- MyBatis与Spring整合 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<!-- MyBatis分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<!-- 日志 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<!-- 其他日志框架的中间转换包 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<!-- Spring进行JSON数据转换依赖 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- JSTL标签库 -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- 引入Servlet容器中相关依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>
</project>
AdminMapper
由mybatis****直接生成
TestHandler
package com.yuanbaoqiang.crowd.mvc.handler;
import com.yuanbaoqiang.crowd.entity.Admin;
import com.yuanbaoqiang.crowd.service.api.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/**
* @description:
* @author: YuanbaoQiang
* @time: 2020/10/31 15:54
*/
@Controller
public class TestHandler {
@Autowired
private AdminService adminService;
@RequestMapping("/test/ssm.html")
public String testSum(Model model){
List<Admin> adminList = adminService.getAll();
model.addAttribute("adminList",adminList);
return "target";
}
}
AdminService
package com.yuanbaoqiang.crowd.service.api;
import com.yuanbaoqiang.crowd.entity.Admin;
import java.util.List;
public interface AdminService {
void saveAdmin(Admin admin);
List<Admin> getAll();
}
AdminServiceImpl
package com.yuanbaoqiang.crowd.service.impl;
import com.yuanbaoqiang.crowd.entity.Admin;
import com.yuanbaoqiang.crowd.entity.AdminExample;
import com.yuanbaoqiang.crowd.mapper.AdminMapper;
import com.yuanbaoqiang.crowd.service.api.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @description:
* @author: YuanbaoQiang
* @time: 2020/10/31 14:16
*/
@Service
public class AdminServiceImpl implements AdminService {
@Autowired
private AdminMapper adminMapper;
@Override
public void saveAdmin(Admin admin) {
adminMapper.insert(admin);
}
@Override
public List<Admin> getAll() {
return adminMapper.selectByExample(new AdminExample());
}
}
atcrowdfunding04-admin-entity
Admin和AdminExample均由mybatis****生成。
atcrowdfunding05-common-util
目前还未涉及。。
atcrowdfunding06-common-reverse
只是用来进行mybatis的****!
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-umj8O2fI-1604384834431)(C:\Users\YuanbaoQiang\AppData\Roaming\Typora\typora-user-images\image-20201103133144143.png)]
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>atcrowdfunding01-admin-parent</artifactId>
<groupId>com.yuanbaoqiang.crowd</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>atcrowdfunding06-common-reverse</artifactId>
<dependencies>
<!--Mybatis依赖-->
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.6</version>
</dependency>
</dependencies>
<!-- 控制Maven 在构建过程中相关配置-->
<build>
<!--构建过程中需要用到的插件-->
<plugins>
<plugin>
<!-- 具体插件,****的操作是以构建过程中插件形式出现的-->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.4.0</version>
<!--插件的依赖-->
<dependencies>
<!--****的核心依赖-->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.4.0</version>
</dependency>
<!-- 数据库连接池 -->
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.5</version>
</dependency>
<!--mysql驱动-->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<!--log4j日志依赖-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
上一篇: SSM框架整合IDEA版
下一篇: IDEA整合SSM框架
推荐阅读