第十篇:Spring Boot整合mybatis+逆向工程(Mysql+Oracle) 入门试炼01

1、添加pom依赖

<dependencies><!--springboot web 启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--thymeleaf 启动器--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId></dependency><!--mybatis启动器--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.0</version></dependency><!--mysql数据库驱动--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.35</version></dependency><!-- alibaba的druid数据库连接池 --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.1.0</version></dependency><!-- 分页插件 --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>1.1.2</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- mybatis generator 自动生成代码插件 --><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.2</version><configuration><configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile><overwrite>true</overwrite><verbose>true</verbose></configuration></plugin></plugins></build>

在这里插入图片描述
2、在resources下面创建generator文件夹

一、逆向工程MySQL

添加generatorConfig.xml配置文件_Mysql数据库

<?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">
<!-- 第二种mybatis逆向生成xml配置 -->
<generatorConfiguration><!-- 需要指明数据库连接器的绝对路径 --><classPathEntrylocation="D:\rep\mysql\mysql-connector-java\5.1.35\mysql-connector-java-5.1.35.jar"/><context id="sqlserverTables" targetRuntime="MyBatis3"><!-- 生成的pojo,将implements Serializable--><plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin><commentGenerator><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="true" /></commentGenerator><!-- 数据库链接URL、用户名、密码 --><!-- <jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://localhost:3306/test"userId="root"password="root"></jdbcConnection>--><!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"connectionURL="jdbc:oracle:thin:@10.1.103.250:1521:orcl"userId="fis"password="fis"/>--><!--默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integertrue,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal--><javaTypeResolver><property name="forceBigDecimals" value="false" /></javaTypeResolver><!--生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java,也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下--><!--<javaModelGenerator targetPackage="com.forezp.entity" targetProject="MAVEN">--><javaModelGenerator targetPackage="com.gblfy.entity" targetProject="./src/main/java"><property name="enableSubPackages" value="true"/><!-- 从数据库返回的值被清理前后的空格  --><property name="trimStrings" value="true" /></javaModelGenerator><!--对应的mapper.xml文件  --><sqlMapGenerator targetPackage="/mybatis/mapper" targetProject="./src/main/resources"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!-- 对应的Mapper接口类文件 --><javaClientGenerator type="XMLMAPPER" targetPackage="com.gblfy.repository" targetProject="./src/main/java"><property name="enableSubPackages" value="true"/></javaClientGenerator><!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名--><table tableName="user" domainObjectName="User"enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"enableSelectByExample="false" selectByExampleQueryId="false" ><property name="useActualColumnNames" value="false"/></table></context>
</generatorConfiguration>

3、指定数据库驱动jar位置
在这里插入图片描述
4、在idea右边查看路径,去本地maven仓库找到jar包
在这里插入图片描述在这里插入图片描述
5、创建表结构

CREATE TABLE `users` (`id` int(11) NOT NULL,`name` varchar(255) COLLATE utf8_bin NOT NULL,`age` int(11) NOT NULL,PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

6、双击插件,运行即可
在这里插入图片描述
7、项目效果图
在这里插入图片描述
6、application.yml添加数据库信息

#服务器端口
server:port: 8082
#mybatis mapper映射文件和扫描实体类配置文件     位置
mybatis:config-location: classpath:/mybatis/config/mybatis-config.xmlmapper-locations: classpath:/mybatis/mapper/*.xml
#mysql数据库驱动 url username  password
spring:datasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=trueusername: rootpassword: root

二、逆向生成_Oracle

1、pom依赖

<!-- Oracle数据库驱动 -->
<dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.3</version>
</dependency>

2、修改generatorConfig.xml文件

<?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">
<!-- 第二种mybatis逆向生成xml配置 -->
<generatorConfiguration><!-- 需要指明数据库连接器的绝对路径 --><classPathEntrylocation="D:\rep\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar"/><context id="sqlserverTables" targetRuntime="MyBatis3"><!-- 生成的pojo,将implements Serializable--><plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin><commentGenerator><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="true" /></commentGenerator><!-- 数据库链接URL、用户名、密码 --><jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"connectionURL="jdbc:oracle:thin:@105.1.10.0:1521:orcl"userId="root"password="root"/><!--默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integertrue,把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal--><javaTypeResolver><property name="forceBigDecimals" value="false" /></javaTypeResolver><!--生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java,也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下--><!--<javaModelGenerator targetPackage="com.forezp.entity" targetProject="MAVEN">--><javaModelGenerator targetPackage="com.gblfy.pojo" targetProject="./src/main/java"><property name="enableSubPackages" value="true"/><!-- 从数据库返回的值被清理前后的空格  --><property name="trimStrings" value="true" /></javaModelGenerator><!--对应的mapper.xml文件  --><sqlMapGenerator targetPackage="mapping" targetProject="./src/main/resources"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!-- 对应的Mapper接口类文件 --><javaClientGenerator type="XMLMAPPER" targetPackage="com.gblfy.dao" targetProject="./src/main/java"><property name="enableSubPackages" value="true"/></javaClientGenerator><!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名--><table tableName="fisurlmapping" domainObjectName="Fisurlmapping"enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"enableSelectByExample="false" selectByExampleQueryId="false" ><property name="useActualColumnNames" value="false"/></table></context>
</generatorConfiguration>

在这里插入图片描述

本文源码下载:

github地址:
https://github.com/gb-heima/Spring-Boot-Actual-Combat/tree/master/parent/spring-boot-chapter-10

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/524198.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Qt中QMap删除元素的简单使用

QMap基本上qt中的使用和C中QMap的使用一样&#xff0c;下面先附上一段代码&#xff1a; void chunzhongForm::deleteScrGroupItem(int screenGroup) {QMap<findInfo,QGraphicsRectItem*>::iterator it;for(it itemMap.begin();it!itemMap.end();){if(it.key().sid scr…

Docker简介与简单使用 | 技术头条

戳蓝字“CSDN云计算”关注我们哦&#xff01;技术头条&#xff1a;干货、简洁、多维全面。更多云计算精华知识尽在眼前&#xff0c;get要点、solve难题&#xff0c;统统不在话下&#xff01;作者&#xff1a;常仕禄转自&#xff1a;Docker前一段花了一段时间研究Log4j2的源码&a…

OpenGL ES EGL eglSwapBuffer

目录 一. EGL 前言二. EGL 绘制流程简介三.eglSwapBuffer 函数简介 四.关于多个 EGLContext五.共享 EGLContext六.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> Open…

第十篇:Spring Boot整合mybatis+Mysql 入门试炼02

前言&#xff1a; 1、(SprigBoot整合SpringMVCMybatis) 2、以thymeleaf作为视图层技术整合 3、springboot版本2.0.5.RELEASE 创建项目 1、添加依赖及启动器 <dependencies><!--springboot web 启动器--><dependency><groupId>org.springframework.boo…

qt获取场景的缩略图

获取场景缩略图的代码如下&#xff1a; void chunzhongForm::getRenderPaint() {QPixmap pixmap(SMALL_W,SMALL_H);pixmap.fill(Qt::transparent);QPainter painter(&pixmap);painter.setRenderHint(QPainter::Antialiasing);scene->render(&painter);pixmap.save(…

要闻君说:台积电将为iPhone生产5纳米A系列芯片?腾讯云TStack与银河麒麟完成互认证……...

关注并标星星CSDN云计算极客头条&#xff1a;速递、最新、绝对有料。这里有企业新动、这里有业界要闻&#xff0c;打起十二分精神&#xff0c;紧跟fashion你可以的&#xff01;每周三次&#xff0c;打卡即read更快、更全了解泛云圈精彩newsgo go go 【4月9日 星期二】云の声音切…

Centos出现-bash: unzip: command not found的解决办法

利用unzip命令解压缩的时候&#xff0c;出现-bash: unzip: command not found的错误 问题定位&#xff1a; unzip——命令没有找到&#xff0c;其原因肯定是没有安装unzip。 解决方案在线安装unzip &#xff1a; 执行命令&#xff1a; yum install -y unzip zip安装成功后就可…

一堆数据中将某一个值相同的数据进行分组

假如一堆数据&#xff0c;每一个数据都有一个标志位&#xff0c;按照标志位值的不同进行划分为不同的组&#xff0c;进行归类。 代码如下&#xff1a; void chunzhongForm::traverseList(winProList &dataList) {int nSize dataList.size();for(int i 0; i < nSize; …

微服务进阶避坑指南 | 技术头条

戳蓝字“CSDN云计算”关注我们哦&#xff01;技术头条&#xff1a;干货、简洁、多维全面。更多云计算精华知识尽在眼前&#xff0c;get要点、solve难题&#xff0c;统统不在话下&#xff01;来源&#xff1a;青云QingCloud 作者&#xff1a;周小四 青云QingCloud 应用及容器平台…

Launch failed - cleaning up connection

Jenkins远程连接ssh(Linux系统)失败 关键信息&#xff1a; Warning: no key algorithms provided; JENKINS-42959 disabled Warning: no key algorithms provided; JENKINS-42959 disabled SSHLauncher{host192.168.45.145, port22, credentialsId61eab5fd-5c3f-4bc7-a794-f87…

前后两组结构相同的数据进行比较,找出新增的,需要删除的,原来存在的

想象现在服务器在向客户端发送数据&#xff0c;每隔几秒发送一次数据&#xff0c;客户端需要将前后两次的数据进行对比&#xff0c;找出相对于收的数据需要将上一次的数据删除的部分&#xff0c;以及此次新增加的&#xff0c;还有原来就已经存在的数据。 代码如下&#xff1a; …

Hadoop精华问答:Hadoop框架最核心的设计是?

2006年项目成立的一开始,“Hadoop”这个单词只代表了两个组件——HDFS和MapReduce。到现在的13个年头,这个单词代表的是“核心”&#xff0c;今天我们就来看看关于Hadoop的精华问答。1Q&#xff1a;Hadoop是什么&#xff1f;A&#xff1a;Hadoop是一个由Apache基金会所开发的分…

git.exe init#timeout = 10错误:克隆远程repo'origin'时出错hudson.plugins.git

用Jenkins自动化搭建测试环境&#xff0c;Jenkins构建任务 关键异常抓取 git.exe init&#xff03;timeout 10错误&#xff1a;克隆远程repoorigin时出错hudson.plugins.git (git.exe init # timeout10 ERROR: Error cloning remote repo origin hudson.plugins.git)具体异常抓…

Qt中绘制直线

绘制多条直线&#xff0c;直接上代码&#xff1a; 绘制直线的部分 QPen pen(Qt::lightGray,1);pen.setStyle(Qt::DashDotDotLine);pen.setWidth(1);painter.setPen(pen);painter.translate(0, 0);painter.drawLines(lines);添加直线代码&#xff1a; for(int i 0; i < rowC…

阿里云镜像仓库

阿里云镜像加速器 第一步&#xff1a;进入apache-maven-3.6.1/conf/目录 cd apache-maven-3.6.1/conf/第二步&#xff1a;编辑settings.xml文件添加阿里云仓库镜像 vim settings.xml第三步&#xff1a;在文件中找到标签&#xff0c;在里面复制添加即可&#xff01; <mirro…

Docker精华问答 | 多个 Docker 容器之间共享数据怎么办?

在计算机技术日新月异的今天, Docker 在国内发展的如火如荼。特别是在一线互联网公司 Docker 的使用是十分普遍的,甚至成为了一些企业面试的加分项&#xff0c;那么今天我们继续关于Docker 的精华问答。1Q&#xff1a;容器磁盘可以限制配额么&#xff1f; A&#xff1a;对于 de…

Qt中多个动态创建的按钮同时绑定一个槽函数,判断被点击的是哪个按钮

当动态创建按钮&#xff0c;每一个创建的按钮都与同一个槽函数绑定&#xff0c;点击按钮的时候获取被点击的按钮的文本。 代码如下&#xff1a; QString getClickedBtn() {outPut<<"getClickedBtn()";QString strText " ";for(int i 0; i < m_…

ssh连接远程linux环境

ssh连接远程linux环境 格式为&#xff1a; ssh 用户名远程ip地址例如&#xff1a; ssh root192.168.182.128

要闻君说:谷歌云重磅发布两大技术平台;以后可以打飞滴了?SAP重组动荡;微软宣布 Azure Functions 支持 Java...

关注并标星星CSDN云计算极客头条&#xff1a;速递、最新、绝对有料。这里有企业新动、这里有业界要闻&#xff0c;打起十二分精神&#xff0c;紧跟fashion你可以的&#xff01;每周三次&#xff0c;打卡即read更快、更全了解泛云圈精彩newsgo go go 【4月10日 星期三】云の声音…

OpenGL ES EGL eglDestroyContext

目录 一. EGL 前言二. EGL 绘制流程简介三.eglDestroyContext 函数简介 四.eglDestroyContext 使用四.猜你喜欢 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> OpenGL ES 基础 零基础 OpenGL ES 学习路线推荐 : OpenGL ES 学习目录 >> OpenGL ES 特效 …