1.添加依赖
<!--mybaits-->
<dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.0.3</version>
</dependency>
打入mybatis.xml
<resources><resource><directory>src/main/java</directory><includes><include>**/*.xml</include></includes></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include><include>**/*.tld</include></includes></resource>
</resources>
加入插件
<plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><dependencies><dependency><groupId>tk.mybatis</groupId><artifactId>mapper</artifactId><version>3.5.0</version></dependency></dependencies><version>1.3.5</version><executions><execution><id>Generate MyBatis Artifacts</id><phase>none</phase><goals><goal>generate</goal></goals></execution></executions>
</plugin>
2.添加generatorConfig.xml mybatis的配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration><!--导入属性配置 --><!--<properties resource="generator.properties"></properties>--><!--指定特定数据库的jdbc驱动jar包的位置 --><classPathEntrylocation="/Users/mac/.m2/repository/mysql/mysql-connector-java/5.1.27/mysql-connector-java-5.1.27.jar"/><context id="MySql" targetRuntime="MyBatis3Simple" defaultModelType="flat"><plugin type="tk.mybatis.mapper.generator.MapperPlugin"><property name="mappers" value="com.example.springbootProvider.mapper.CommonMapper"/><!-- caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true --><property name="caseSensitive" value="true"/></plugin><!-- optional,旨在创建class时,对注释进行控制 --><commentGenerator><property name="suppressDate" value="true"/><property name="suppressAllComments" value="true"/></commentGenerator><!--jdbc的数据库连接 --><jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://101.132.33.149:3306/shenzepeng?useSSL=false"userId="root"
password="123456">
</jdbcConnection><!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制--><javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver><!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类targetPackage 指定生成的model生成所在的包名targetProject 指定在该项目下所在的路径--><javaModelGenerator targetPackage="com.example.springbootProvider.model" targetProject="src/main/java"><!-- 是否对model添加 构造函数 --><!--<property name="constructorBased" value="true"/>--><!-- 是否允许子包,即targetPackage.schemaName.tableName --><property name="enableSubPackages" value="false"/><!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 --><property name="immutable" value="false"/><!-- 给Model添加一个父类 --><!--<property name="rootClass" value="com."/>--><!-- 是否对类CHAR类型的列的数据进行trim操作 --><property name="trimStrings" value="true"/></javaModelGenerator><sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/><javaClientGenerator targetPackage="com.example.springbootProvider.mapper" targetProject="src/main/java"type="XMLMAPPER"><!--<property name="enableSubPackages" value=""/>--><!--定义Maper.java 源代码中的ByExample() 方法的可视性,可选的值有:public;private;protected;default注意:如果 targetRuntime="MyBatis3",此参数被忽略--><!--<property name="exampleMethodVisibility" value=""/>--><!--方法名计数器Important note: this property is ignored if the target runtime is MyBatis3.--><!--<property name="methodNameCalculator" value=""/>--><!--为生成的接口添加父接口--></javaClientGenerator><table tableName="alarm_mail_info" domainObjectName="AlarmMailInfo"><generatedKey column="id" sqlStatement="MySql" identity="true"/></table><!--<table tableName="alarm_sms_info" domainObjectName="AlarmSmsInfo">--><!--<generatedKey column="id" sqlStatement="MySql" identity="true"/>--><!--</table>--><table tableName="alarm_wxmp_info" domainObjectName="AlarmWxmpInfo"><generatedKey column="id" sqlStatement="MySql" identity="true"/></table></context>
</generatorConfiguration>
3.添加application.properties
###########dubbo#######################
dubbo.application.name = dubbo-demo-server
dubbo.scan.basePackages= com.example.springbootProvider.provider
## RegistryConfig Bean
dubbo.registry.id = my-registry
dubbo.protocol.port=20880
dubbo.registry.address = zookeeper://www.shenzepengzuishuai.cn:2181?client=curator
mybatis.mapper-locations=classpath:/mapper/*.xml#####################################
server.port=8080
#配置数据源
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#mysql的驱动程序类
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#mybatis配置
mybatis.type-aliases-package=com.example.uniapp_test1.pojo
#连接池配置
spring.datasource.url=jdbc:mysql://xxxxx:3306/uniapp_test?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.dbcp2.min-idle=5
spring.datasource.dbcp2.initial-size=5
spring.datasource.dbcp2.max-idle=5
spring.datasource.dbcp2.max-wait-millis=200
#####################################
4.更改relativePath
<parent><groupId>com.example</groupId><artifactId>springboot</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
5.添加druid依赖
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.10</version>
</dependency>
6.在mapper中添加公共mapper CommonMapper.java
import tk.mybatis.mapper.common.Mapper;import tk.mybatis.mapper.common.MySqlMapper;public interface CommonMapper<T> extends Mapper<T>, MySqlMapper<T> {
}
7.在provider中的pom添加这个插件 因为在没有xml的情况下无法打包
<plugin><artifactId>maven-war-plugin</artifactId><version>2.6</version><configuration><!--如果想在没有web.xml文件的情况下构建WAR,请设置为false。--><failOnMissingWebXml>false</failOnMissingWebXml></configuration>
</plugin>