我是靠谱客的博主 简单服饰,最近开发中收集的这篇文章主要介绍GitLab的开发流程之企业级工程搭建-03创建数据库管理项目(mybatis逆向工程)首先感谢千峰教育的学习视频GitLab的开发流程之企业级工程搭建-03创建数据库管理项目,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
首先感谢千峰教育的学习视频
GitLab的开发流程之企业级工程搭建-03创建数据库管理项目
1.在GitLab上新建项目
2.Git克隆
3.继续在IDEA新建模块 new module ->springboot,拷贝过滤文件
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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nelsoner.gaming</groupId>
<artifactId>gaming-server-database</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>gaming-server-database</name>
<description></description>
<parent>
<groupId>com.nelsoner.gaming</groupId>
<artifactId>gaming-server-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.4.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
application.yml
spring:
datasource:
druid:
url: jdbc:mysql:///ajax?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
driver-class-name: com.mysql.jdbc.Driver
mybatis:
type-aliases-package: com.nelsoner.gaming.server.database.domain
mapper-locations: classpath:mapper/*.xml
4.自定义 MyMapper 接口
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
/**
* 自己的 Mapper
* 特别注意,该接口不能被扫描到,否则会出错
*/
public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> {
}
5.自动生成配置
在 src/main/resources/generator/
目录下创建 generatorConfig.xml
配置文件:
<?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>
<properties resource="jdbc.properties"/>
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.nelsoner.gaming.server.utils.MyMapper"/>
</plugin>
<jdbcConnection
driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.username}"
password="${jdbc.password}">
</jdbcConnection>
<javaModelGenerator targetPackage="com.nelsoner.gaming.server.database.domain" targetProject="src/main/java"/>
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
<javaClientGenerator
targetPackage="com.nelsoner.gaming.server.database.mapper"
targetProject="src/main/java"
type="XMLMAPPER"/>
<table tableName="%">
<!-- mysql 配置 -->
<generatedKey column="id" sqlStatement="Mysql" identity="true"/>
</table>
</context>
</generatorConfiguration>
6.数据源配置
在 src/main/resources
目录下创建 jdbc.properties
数据源配置:
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql:///ajax?useUnicode=true&characterEncoding=utf-8&useSSL=false
jdbc.username=root
jdbc.password=123456
7.生成代码
mvn mybatis-generator:generate
生成成功
最后
以上就是简单服饰为你收集整理的GitLab的开发流程之企业级工程搭建-03创建数据库管理项目(mybatis逆向工程)首先感谢千峰教育的学习视频GitLab的开发流程之企业级工程搭建-03创建数据库管理项目的全部内容,希望文章能够帮你解决GitLab的开发流程之企业级工程搭建-03创建数据库管理项目(mybatis逆向工程)首先感谢千峰教育的学习视频GitLab的开发流程之企业级工程搭建-03创建数据库管理项目所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复