众筹项目之环境配置(一)

1. 环境搭建总体目标

在这里插入图片描述

2. 创建工程

2.1 项目构架图

在这里插入图片描述

2.2 工程创建计划

atcrowdfunding01-admin-parent
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding01-admin-parent
		packaging: pom
atcrowdfunding02-admin-webui
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding02-admin-parent
		packaging: war
atcrowdfunding03-admin-component
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding03-component
		packaging:jar
atcrowdfunding04-admin-entity
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding04-entity
		packaging:jar
atcrowdfunding05-admin-util
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding05-util
		packaging:jar
atcrowdfunding06-admin-reverse
		grouold: com.atguigu.crowd
		artifactld: atcrowdfunding06-reverse
		packaging:jar

2.4 建立工程之间的依赖关系

webui依赖于component
component依赖于entity
component依赖于util

在这里插入图片描述

在这里插入图片描述

3. 创建数据库和数据库表

3.1 物理建模

3.1.1 理论

第一范式:数据库表中的每一列都不可再分,也就是原子性
在这里插入图片描述
这个表中“部门”和“岗位”应该拆分成两个字段:“部门名称”、“岗位”

在这里插入图片描述
这样才能够专门针对“部门”或“岗位”进行查询。

第二范式:在满足第一范式基础上要求每个字段都和主键完整相关,而不是仅和主键部分相关(主要针对联合主键而言)
在这里插入图片描述
“订单详情表”使用“订单编号”和“产品编号”作为联合主键。此时“产
品价格”、“产品数量”都和联合主键整体相关,但“订单金额”和“下单时间”
只和联合主键中的“订单编号”相关,和“产品编号”无关。所以只关联了主
键中的部分字段,不满足第二范式。

把“订单金额”和“下单时间”移到订单表就符合第二范式了。
在这里插入图片描述
第三范式:表中的非主键字段和主键字段直接相关,不允许间接相关
在这里插入图片描述
上面表中的“部门名称”和“员工编号”的关系是“员工编号”→“部门编号”
→“部门名称”,不是直接相关。此时会带来下列问题:

数据冗余:“部门名称”多次重复出现。
插入异常:组建一个新部门时没有员工信息,也就无法单独插入部门
信息。就算强行插入部门信息,员工表中没有员工信息的记录同样是
非法记录。
删除异常:删除员工信息会连带删除部门信息导致部门信息意外丢失。
更新异常:哪怕只修改一个部门的名称也要更新多条员工记录。
正确的做法是:把上表拆分成两张表,以外键形式关联

在这里插入图片描述
“部门编号”和“员工编号”是直接相关的。
第二范式的另一种表述方式是:两张表要通过外键关联,不保存冗余字段。例
如:不能在“员工表”中存储“部门名称”。

3.1.2 实践

规则的变通
三大范式是设计数据库表结构的规则约束,但是在实际开发中允许局部变
通。
比如为了快速查询到关联数据可能会允许冗余字段的存在。例如在员工表
中存储部门名称虽然违背第三范式,但是免去了对部门表的关联查询。

根据业务功能设计数据库表

看得见的字段
能够从需求文档或原型页面上直接看到的数据都需要设计对应的数
据库表、字段来存储。
在这里插入图片描述
根据上面的原型页面我们看到管理员表需要包含如下字段:
-账号
-密码
-名称
-邮箱地址
看不见的字段
除了能够直接从需求文档中看到的字段,实际开发中往往还会包含一
些其他字段来保存其他相关数据。
例如:管理员表需要再增加如下字段以有利于数据维护
-主键
-创建时间
冗余字段
为了避免建表时考虑不周有所遗漏,到后期再修改表结构非常麻烦,
所以也有的团队会设置一些额外的冗余字段备用。
实际开发对接
实际开发中除了一些各个模块都需要使用的公共表在项目启动时创
建好,其他专属于各个模块的表由该模块的负责人创建。但通常开发人员
不能直接操作数据库服务器,所以需要把建表的 SQL 语句发送给运维工程
师执行创建操作

3.2 创建数据库

CREATE DATABASE project_crowd CHARACTER SET utf8;

3.3 创建管理员数据库表

use project_crowd;
drop table if exists t_admin;
create table t_admin
(
id int not null auto_increment, # 主键
login_acct varchar(255) not null,
# 登录账号
user_pswd char(32) not null,# 登录密码
user_name varchar(255) not null,# 昵称
email varchar(255) not null,# 邮件地址
create_time char(19),# 创建时间
primary key (id)
);

在这里插入图片描述

4. 基于 Maven 的 MyBatis 逆向工程

4.1 pom 配置

 <modelVersion>4.0.0</modelVersion>

    <groupId>com.atguigu.crowd</groupId>
    <artifactId>atcrowdfunding06-common-reverse</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <!-- 依赖 MyBatis 核心包 -->
    <dependencies>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.8</version>
        </dependency>
    </dependencies>
    <!-- 控制 Maven 在构建过程中相关配置 -->
    <build>
    <!-- 构建过程中用到的插件 -->
    <plugins>
    <!-- 具体插件,逆向工程的操作是以构建过程中插件形式出现的 -->
        <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
         <version>1.3.0</version>
    <!-- 插件的依赖 -->
            <dependencies>
    <!-- 逆向工程的核心依赖 -->
             <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
        <version>1.3.2</version>
    </dependency>
    <!-- 数据库连接池 -->
    <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.2</version>
    </dependency>
        <!-- MySQL 驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.8</version>
        </dependency>
    </dependencies>
    </plugin>
    </plugins>
    </build>

4.2 generatorConfig.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!-- mybatis-generator:generate -->
    <context id="atguiguTables" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:;false:-->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        <jdbcConnection
                driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:3306/project_crowd"
                userId="root"
                password="root">
        </jdbcConnection>
        <!-- 默认 false,把 JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true 时把
        JDBC DECIMAL
        和 NUMERIC 类型解析为 java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- targetProject:生成 Entity 类的路径 -->
        <javaModelGenerator targetProject=".\src\main\java"
                            targetPackage="entity">
            <!-- enableSubPackages:是否让 schema 作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
            <!-- 从数据库返回的值被清理前后的空格 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- targetProject:XxxMapper.xml 映射文件生成的路径 -->
        <sqlMapGenerator targetProject=".\src\main\java"
                         targetPackage="mapper">
            <!-- enableSubPackages:是否让 schema 作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>
        <!-- targetPackage:Mapper 接口生成的位置 -->
        <javaClientGenerator type="XMLMAPPER"
                             targetProject=".\src\main\java"
                             targetPackage="mapper">
            <!-- enableSubPackages:是否让 schema 作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        <!-- 数据库表名字和我们的 entity 类对应的映射指定 -->
        <table tableName="t_admin" domainObjectName="Admin" />
    </context>
</generatorConfiguration>

4.3 执行逆向生成操作的 Maven 命令

mybatis-generator:generate
在这里插入图片描述

4.4 逆向工程生成的资源各归各位

WebUI 工程将来在 Tomcat 上运行时,现在 resources 目录下的资源会直接放在
WEB-INF/classes 目录(也就是类路径)下,所以放在 resources 目录下运行的时候更容
易找到

5. 父工程依赖管理

5.1 版本声明

在这里插入图片描述

<properties>
        <!-- 声明属性,对 Spring 的版本进行统一管理 -->
        <atguigu.spring.version>4.3.20.RELEASE</atguigu.spring.version>
        <!-- 声明属性,对 SpringSecurity 的版本进行统一管理 -->
        <atguigu.spring.security.version>4.2.10.RELEASE</atguigu.spring.security.version>
    </properties>

5.2 依赖管理

<dependencyManagement>
		<dependencies>
			<!-- Spring依赖 -->
			<!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-orm</artifactId>
				<version>${atguigu.spring.version}</version>
			</dependency>
			<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-webmvc</artifactId>
				<version>${atguigu.spring.version}</version>
			</dependency>
			<dependency>
				<groupId>org.springframework</groupId>
				<artifactId>spring-test</artifactId>
				<version>${atguigu.spring.version}</version>
			</dependency>
			<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
			<dependency>
				<groupId>org.aspectj</groupId>
				<artifactId>aspectjweaver</artifactId>
				<version>1.9.2</version>
			</dependency>
			<!-- https://mvnrepository.com/artifact/cglib/cglib -->
			<dependency>
				<groupId>cglib</groupId>
				<artifactId>cglib</artifactId>
				<version>2.2</version>
			</dependency>

			<!-- 数据库依赖 -->
			<!-- MySQL驱动 -->
			<dependency>
				<groupId>mysql</groupId>
				<artifactId>mysql-connector-java</artifactId>
				<version>5.1.3</version>
			</dependency>

			<!-- 数据源 -->
			<dependency>
				<groupId>com.alibaba</groupId>
				<artifactId>druid</artifactId>
				<version>1.0.31</version>
			</dependency>

			<!-- MyBatis -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis</artifactId>
				<version>3.2.8</version>
			</dependency>

			<!-- MyBatisSpring整合 -->
			<dependency>
				<groupId>org.mybatis</groupId>
				<artifactId>mybatis-spring</artifactId>
				<version>1.2.2</version>
			</dependency>

			<!-- MyBatis分页插件 -->
			<dependency>
				<groupId>com.github.pagehelper</groupId>
				<artifactId>pagehelper</artifactId>
				<version>4.0.0</version>
			</dependency>

			<!-- 日志 -->
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>slf4j-api</artifactId>
				<version>1.7.7</version>
			</dependency>
			<dependency>
				<groupId>ch.qos.logback</groupId>
				<artifactId>logback-classic</artifactId>
				<version>1.2.3</version>
			</dependency>

			<!-- 其他日志框架的中间转换包 -->
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>jcl-over-slf4j</artifactId>
				<version>1.7.25</version>
			</dependency>
			<dependency>
				<groupId>org.slf4j</groupId>
				<artifactId>jul-to-slf4j</artifactId>
				<version>1.7.25</version>
			</dependency>

			<!-- Spring进行JSON数据转换依赖 -->
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-core</artifactId>
				<version>2.9.8</version>
			</dependency>
			<dependency>
				<groupId>com.fasterxml.jackson.core</groupId>
				<artifactId>jackson-databind</artifactId>
				<version>2.9.8</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容器中相关依赖 -->
			<dependency>
				<groupId>javax.servlet</groupId>
				<artifactId>servlet-api</artifactId>
				<version>2.5</version>
				<scope>provided</scope>
			</dependency>

			<!-- JSP页面使用的依赖 -->
			<dependency>
				<groupId>javax.servlet.jsp</groupId>
				<artifactId>jsp-api</artifactId>
				<version>2.1.3-b06</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.5</version>
			</dependency>

			<!-- SpringSecurityWeb 应用进行权限管理 -->
			<dependency>
				<groupId>org.springframework.security</groupId>
				<artifactId>spring-security-web</artifactId>
				<version>4.2.10.RELEASE</version>
			</dependency>
			<!-- SpringSecurity 配置 -->
			<dependency>
				<groupId>org.springframework.security</groupId>
				<artifactId>spring-security-config</artifactId>
				<version>4.2.10.RELEASE</version>
			</dependency>
			<!-- SpringSecurity 标签库 -->
			<dependency>
				<groupId>org.springframework.security</groupId>
				<artifactId>spring-security-taglibs</artifactId>
				<version>4.2.10.RELEASE</version>
			</dependency>
		</dependencies>
	</dependencyManagement>

5.3 依赖信息来源

到专门网站搜索
https://mvnrepository.com
调试
根据实际运行情况,确认 jar 包之间是否兼容
SpringMVC 需要 jackson 的支持,来处理 JSON 数据。但是 SpringMVC 并没有依赖 jackson。所以需要我们自己保证 jar 包之间的兼容性。

6. Spring 整合 MyBatis

6.1 目标

adminMapper 通过 IOC 容器装配到当前组件中后,就可以直接调用它的方法,享受到框架给我们提供的方便
在这里插入图片描述

6.2 思路

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

6.3 操作清单

在子工程中加入搭建环境所需要的具体依赖
准备 jdbc.properties
创建 Spring 配置文件专门配置 Spring 和 MyBatis 整合相关
在 Spring 的配置文件中加载 jdbc.properties 属性文件
配置数据源
测试从数据源中获取数据库连接
配置 SqlSessionFactoryBean
装配数据源
指定 XxxMapper.xml 配置文件的位置
指定 MyBatis 全局配置文件的位置(可选)
配置 MapperScannerConfigurer
测试是否可以装配 XxxMapper 接口并通过这个接口操作数据库

6.4 操作步骤详解

6.4.1 在子工程中加入搭建环境所需的具体依赖

在这里插入图片描述

<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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.atguigu.crowd</groupId>
        <artifactId>atcrowdfunding01-admin-parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>atcrowdfunding03-admin-component</artifactId>
    <dependencies>
        <dependency>
            <groupId>com.atguigu.crowd</groupId>
            <artifactId>atcrowdfunding04-admin-entity</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.atguigu.crowd</groupId>
            <artifactId>atcrowdfunding05-common-util</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- Spring依赖 -->
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </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>

        <!-- 数据源 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
        </dependency>

        <!-- MyBatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </dependency>

        <!-- MyBatisSpring整合 -->
        <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>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <!--&lt;!&ndash; JSP 页面使用的依赖 &ndash;&gt;-->
        <!--<dependency>-->
            <!--<groupId>javax.servlet.jsp</groupId>-->
            <!--<artifactId>jsp-api</artifactId>-->
            <!--<version>2.1.3-b06</version>-->
            <!--<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>

6.4.2 数据库连接信息

在这里插入图片描述

jdbc.user=root
jdbc.password=root
jdbc.url=jdbc:mysql://localhost:3306/project_crowd?useUnicode=true&characterEncoding=UTF-8
jdbc.driver=com.mysql.jdbc.Driver

6.4.3 mybatis-config.xml

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

</configuration>

6.4.4 创建 spring-persist-mybatis.xml

在这里插入图片描述

6.4.5 Spring 具体配置:第一步 配置数据源

<?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 http://www.springframework.org/schema/context/spring-context-2.5.xsd" >


        <!-- 加载外部属性文件-->
        <context:property-placeholder location="classpath:jdbc.properties"/>

        <!-- 配置数据源-->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
            <property name="username" value="${jdbc.user}"/>
            <property name="password" value="${jdbc.password}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="driverClassName" value="${jdbc.driver}"/>
        </bean>
       

        <
</beans>

测试

加入测试依赖
在这里插入图片描述

<!-- junit测试 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <scope>test</scope>
            <!--<exclusions>-->
                <!--<exclusion>-->
                    <!--<artifactId>commons-logging</artifactId>-->
                    <!--<groupId>commons-logging</groupId>-->
                <!--</exclusion>-->
            <!--</exclusions>-->
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

在这里插入图片描述

// 指定 Spring 给 Junit 提供的运行器类
@RunWith(SpringJUnit4ClassRunner.class)
// 加载 Spring 配置文件的注解
@ContextConfiguration(locations = {"classpath:spring-persist-mybatis.xml","classpath:spring-persist-tx.xml"})
public class CrowdTest {
	
	@Autowired
	private DataSource dataSource
	
 @Test
    public void testConnection() throws SQLException{

        // 1.通过数据源对象获取数据源连接
        Connection connection = dataSource.getConnection();
        // 2.打印数据库连接
        System.out.println(connection);
        System.out.println("-------------------");
    }
}

在这里插入图片描述

6.4.6 Spring 具体配置:第二步 配置 SqlSessionFactoryBean

在这里插入图片描述

 <!-- 配置SqlSessionFactoryBean整合MyBatis-->
        <bean id="SqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
            <!-- 指定MyBatis全局配置文件位置-->
            <property name="configLocation" value="classpath:mybatis-config.xml"/>

            <!-- 指定Mapper.xml配置文件位置-->
            <property name="mapperLocations" value="classpath:mybatis/mapper/*Mapper.xml"/>

            <!-- 配置数据源-->
            <property name="dataSource" ref="dataSource"/>
        </bean>

6.4.7 Spring 具体配置:第三步 配置 MapperScannerConfigurer

在这里插入图片描述

<!-- 配置 MapperScannerConfigurer -->
        <!-- 配置MapperScannerConfigurer来扫描Mapper接口所在的包-->
        <bean id="MapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <!-- 使用 basePackage 属性指定 Mapper 接口所在包 -->
            <property name="basePackage" value="com.atguigu.crowd.mapper"/>
        </bean>

测试

@Autowired
private AdminService adminService;
@Test
public void testAdminMapperAutowired() {
Admin admin = adminService.getAdminById(1);
System.out.println(admin);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值