1.参考:

简单整合,会报错误

https://segmentfault.com/a/1190000040467885?utm_source=sf-similar-article

利用maven编译,

https://blog.csdn.net/zhiweihongyan1/article/details/120848199?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164592123216780274162555%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164592123216780274162555&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-5-120848199.pc_search_result_cache&utm_term=fluent+mybatis&spm=1018.2226.3001.4187

打开目标显示才不会错误。

2. 新建工程

附:idea 建立spring-boot程序抓图:参考连接。  https://www.cnblogs.com/cqmcu/p/15926462.html

添加pom

<properties>
<java.version>1.8</java.version>
<fluent-mybatis.version>1.6.13</fluent-mybatis.version>
</properties> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency> <!-- 引入fluent-mybatis 运行依赖包, scope为compile -->
<dependency>
<groupId>com.github.atool</groupId>
<artifactId>fluent-mybatis</artifactId>
<version>${fluent-mybatis.version}</version>
</dependency>
<!-- 引入fluent-mybatis-processor, scope设置为provider 编译需要,运行时不需要 -->
<dependency>
<groupId>com.github.atool</groupId>
<artifactId>fluent-mybatis-processor</artifactId>
<version>${fluent-mybatis.version}</version>
<!-- <scope>provided</scope>-->
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin> <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

注意,mawen编译插件,没有则有问题。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>

3. application.yml配置

server:
port: 8080 # 端口号
spring:
datasource: # 数据库参数配置
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf8
username: root
password: 123456

4.  EntityGeneratorTests.java 自动代码生成

package com.example.helloworld;

import cn.org.atool.generator.FileGenerator;
import cn.org.atool.generator.annotation.Table;
import cn.org.atool.generator.annotation.Tables;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest
public class EntityGeneratorTests { // 数据源 url
static final String url = "jdbc:mysql://127.0.0.1:3306/test_db?useUnicode=true&characterEncoding=utf8";
// 数据库用户名
static final String username = "root";
// 数据库密码
static final String password = "123456"; @Test
public void generate() {
// 引用配置类,build方法允许有多个配置类
FileGenerator.build(Empty.class);
} @Tables(
// 设置数据库连接信息
url = url, username = username, password = password,
// 设置entity类生成src目录, 相对于 user.dir
srcDir = "src/main/java",
// 设置entity类的package值
basePack = "com.example.helloworld",
// 设置dao接口和实现的src目录, 相对于 user.dir
daoDir = "src/main/java",
// 设置哪些表要生成Entity文件
tables = {@Table(value = {"person"})}
)
static class Empty { //类名随便取, 只是配置定义的一个载体
} }

5. 利用maven编译

 6.显示target

 7.编译产生代码

8. 产生目标代码

9.添加映射扫描

 10.Controller测试代码编写

@RestController
@RequestMapping("/person")
public class PersonController {
@Resource
PersonDao personDao; @Resource
PersonMapper personMapper; //数据库的操作:增删改查
/**
* 根据ID查询数据1
* @param id
* @return
*/
@GetMapping("/getById")
public PersonEntity getById(Integer id){
return personDao.selectById(id);
} /**
* 根据ID删除
* @param id
*/
@GetMapping("/deleteById")
public void deleteById(Integer id){
personDao.deleteById(id);
} /**
* 根据ID进行更新
* @param personEntity
* @return
*/
@PostMapping("/updateById")
public PersonEntity updateById(@RequestBody PersonEntity personEntity){
boolean b = personDao.updateById(personEntity);
if (b){
return personDao.selectById(personEntity.getId());
}
return null;
} /**
* 新增
* @param personEntity
* @return
*/
@PostMapping("/insert")
public Integer insert(@RequestBody PersonEntity personEntity){
return personDao.save(personEntity);
} }

11.利用postman工具测试

12-完整代码下载地址:

链接:https://pan.baidu.com/s/1YCuKfQHFyCmIVxkYFnHIOw
提取码:ca61
--来自百度网盘超级会员V5的分享

 


实验: spring-boot 整合 fluent-mybatis 实验过程!!!!的更多相关文章

  1. Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程

    Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...

  2. spring boot 2.x 系列 —— spring boot 整合 druid+mybatis

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构 项目查询用的表对应的建表语句放置在resour ...

  3. spring boot整合 springmvc+mybatis

    需要以下依赖 <dependencies> <dependency> <groupId>org.springframework.boot</groupId&g ...

  4. Spring Boot 整合 Druid

    Spring Boot 整合 Druid 概述 Druid 是阿里巴巴开源平台上的一个项目,整个项目由数据库连接池.插件框架和 SQL 解析器组成.该项目主要是为了扩展 JDBC 的一些限制,可以让程 ...

  5. Spring Boot整合Mybatis并完成CRUD操作

    MyBatis 是一款优秀的持久层框架,被各大互联网公司使用,本文使用Spring Boot整合Mybatis,并完成CRUD操作. 为什么要使用Mybatis?我们需要掌握Mybatis吗? 说的官 ...

  6. spring boot 整合 mybatis 以及原理

    同上一篇文章一样,spring boot 整合 mybatis过程中没有看见SqlSessionFactory,sqlsession(sqlsessionTemplate),就连在spring框架整合 ...

  7. 适合初学者的一个分布式环境搭建过程(spring boot + zookeeper + dubbo + mybatis + mysql)

    本人也是才开始接触 阿里巴巴的开源分布式框架 dubbo,因为现在微服务框架 spring boot也非常的火,然后结合dubbo的官网搭建这个开发环境. 一.首先 zookeeper作为集群管理服务 ...

  8. Spring boot整合Mybatis

    时隔两个月的再来写博客的感觉怎么样呢,只能用“棒”来形容了.闲话少说,直接入正题,之前的博客中有说过,将spring与mybatis整个后开发会更爽,基于现在springboot已经成为整个业界开发主 ...

  9. Spring Boot 中使用 MyBatis 整合 Druid 多数据源

    2017 年 10 月 20 日   Spring Boot 中使用 MyBatis 整合 Druid 多数据源 本文将讲述 spring boot + mybatis + druid 多数据源配置方 ...

  10. Spring Boot 整合mybatis时遇到的mapper接口不能注入的问题

    现实情况是这样的,因为在练习spring boot整合mybatis,所以自己新建了个项目做测试,可是在idea里面mapper接口注入报错,后来百度查询了下,把idea的注入等级设置为了warnin ...

随机推荐

  1. 导出PDF 空白赋值备份

    后台代码 //出货清单 @RequestMapping(params="getBusinessOutDetail") public void getBusinessOutDetai ...

  2. redis 0: "AUTH <password> called without any password configured for the def

    运行项目的时候,报redis 0: "AUTH <password> called without any password configured for the def 原因: ...

  3. 下载接口时出现:Try to run this command from the system terminal. Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 'D:\python\demo\venv\Scripts\...的错误

    下载接口时出现:Try to run this command from the system terminal. Make sure that you use the correct version ...

  4. web执行shell脚本

    转载请注明来源:https://www.cnblogs.com/Sherlock-L/p/15584456.html 缘起 去年写过一个shell脚本用来校验统计打点,工作使用.发现同事不太熟悉这块, ...

  5. Vue.js的使用经验

    Vue.js的使用经验   Vue.js的意义 解耦了视图与数据 可复用的组件 前端路由 状态管理 虚拟DOM Vue提供了很多实例属性与方法,都以$开头 $el可以访问挂载Vue实例的元素. $se ...

  6. 在Windows上安装torch遇到的部分问题

    1.版本问题 老师新买的这台机器是RTX 3060,没动显卡驱动,直接安装的CUDA,装的11.4,完全按照这篇blog来的,非常舒服:https://blog.csdn.net/qq_4504187 ...

  7. vue3 门户网站搭建1-路由

    从 0 到 1搭建门户网站,记录一下. 因为需求不大,所以比较简单,门户和后台管理直接一个项目出来,路由配置则想的是: 1.门户,用  /portal 标识 2.后台管理,用 /admin 标识 3. ...

  8. Java基础——IO基础知识

    字节流可以处理任何类型的数据(图片.MP3.视频等文件),字符流只能处理字符类型(文本文件)的数据.

  9. -bash: nslookup: 未找到命令;centos7 安装nslookup

    一.安装服务 [root@localhost ~]# yum -y install bind-utils 二.查看 [root@localhost ~]# nslookup

  10. 基于ipset的dns代理

    ###基于源IP的dns白名单 sleep 60s/etc/init.d/firewall restart ###创建ipset集合 命名为src_dns_whitelist#清空原有命名为src_d ...