一、配置application.properties
#指定bean所在包,默认值为 /**
mybatis.type-aliases-package=com.neusoft.domain
#指定映射文件
# 默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,这里设置要指向的路径,多个使用英文逗号隔开
mybatis.mapperLocations=classpath:mapper/*.xml
二、Spring Boot的pom配置
添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.19</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.41</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>weibo4j-oauth2</artifactId>
<version>2.1.1-beta2-3</version>
</dependency>
三、在resources目录下创建mapper包
将所有的xml文件放置此处
四、mybatis配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- 引入配置文件 -->
<!-- 指定数据连接驱动jar地址 -->
<classPathEntry location="D:\MavenRepository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库的相关配置 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/community" userId="root" password="root">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 实体类生成的位置 -->
<javaModelGenerator targetPackage="com.neusoft.domain" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- *Mapper.xml 文件的位置 ,targetPackage:包名,targetProject:项目下的路径-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- Mapper 接口文件的位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.neusoft.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 配置表信息 -->
<!--第三方服务类型-->
<!--<table tableName="tab_user" domainObjectName="User2" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
<!--xxtable-->
<!--如果生成n个表,那就将上面的那段table代码copy n份-->
</context>
</generatorConfiguration>
四、mybatis配置文件
启动
image.png
网友评论