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的配置文件
- "1.0" encoding="UTF-8"?>
- generatorConfiguration
- PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
- "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
- <generatorConfiguration>
-
-
-
-
- <classPathEntry
- location="/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"/>
-
- <property name="caseSensitive" value="true"/>
- plugin>
-
- <commentGenerator>
- <property name="suppressDate" value="true"/>
- <property name="suppressAllComments" value="true"/>
- commentGenerator>
-
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://101.132.33.149:3306/shenzepeng?useSSL=false"
- userId="root"
- password="123456">
- jdbcConnection>
-
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false"/>
- javaTypeResolver>
-
- <javaModelGenerator targetPackage="com.example.springbootProvider.model" targetProject="src/main/java">
-
-
-
- <property name="enableSubPackages" value="false"/>
-
- <property name="immutable" value="false"/>
-
-
-
- <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">
-
-
-
-
-
-
-
- javaClientGenerator>
- <table tableName="alarm_mail_info" domainObjectName="AlarmMailInfo">
- <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>