springboot + mybatis +druid
Druid Spring Boot Starter
mybatis-spring-boot-autoconfigure
mybatis-spring-boot-samples
新建spring boot工程,添加pom依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
新增User类
public class User {
private Integer id;
private String name;
private Integer sex;
private Integer age;
public User(String name, Integer sex, Integer age) {
this.name = name;
this.sex = sex;
this.age = age;
}
public User(Integer id, String name, Integer sex, Integer age) {
this.id = id;
this.name = name;
this.sex = sex;
this.age = age;
}
public User() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSex() {
return sex;
}
public void setSex(Integer sex) {
this.sex = sex;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
新增UserMapper接口
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select; @Mapper
public interface UserMapper {
@Select("select * from person where id=#{id}")
User findById(@Param("id") Integer id);
}
新增UserController
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; @RestController
public class UserController {
@Autowired
UserMapper userMapper; @RequestMapping(value = "/hello",method = RequestMethod.GET)
public String index() {
User user=userMapper.findById(1);
return user.getName();
}
}
配置文件
spring.datasource.url= jdbc:mysql://192.168.31.146:3306/mydb
spring.datasource.username= root
spring.datasource.password= pass spring.datasource.druid.url= jdbc:mysql://192.168.31.146:3306/mydb
spring.datasource.druid.username= root
spring.datasource.druid.password= pass spring.datasource.druid.initial-size=
spring.datasource.druid.max-active=
spring.datasource.druid.min-idle=
spring.datasource.druid.max-wait=
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=
#spring.datasource.druid.max-open-prepared-statements=
spring.datasource.druid.validation-query=select from dual
#spring.datasource.druid.validation-query-timeout=
spring.datasource.druid.test-on-borrow=false
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=true
spring.datasource.druid.time-between-eviction-runs-millis=
spring.datasource.druid.min-evictable-idle-time-millis=
#spring.datasource.druid.max-evictable-idle-time-millis=
#配置多个英文逗号分隔
spring.datasource.druid.filters=stat,wall,log4j
启动应用后打开浏览器:http://localhost:8080/druid/index.html
再打开:http://localhost:8080/hello
在druid界面查看sql

springboot + mybatis +druid的更多相关文章
- 基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建
基于Maven的Springboot+Mybatis+Druid+Swagger2+mybatis-generator框架环境搭建 前言 最近做回后台开发,重新抓起以前学过的SSM(Spring+Sp ...
- 3分钟搞定SpringBoot+Mybatis+druid多数据源和分布式事务
文章来自: https://blog.csdn.net/qq_29242877/article/details/79033287 在一些复杂的应用开发中,一个应用可能会涉及到连接多个数据源,所谓多数据 ...
- springboot+mybatis+druid+atomikos框架搭建及测试
前言 因为最近公司项目升级,需要将外网数据库的信息导入到内网数据库内.于是找了一些springboot多数据源的文章来看,同时也亲自动手实践.可是过程中也踩了不少的坑,主要原因是我看的文章大部分都是s ...
- springboot+mybatis+druid+sqlite/mysql/oracle
搭建springboot+mybatis+druid+sqlite/mysql/oracle附带测试 1.版本 springboot2.1.6 jdk1.8 2.最简springboot环境 http ...
- 记录一下自己搭建springboot+mybatis+druid 多数据源的过程
前言 上次的一个项目(springboot+mybatis+vue),做到后面的时间发现需要用到多数据源.当时没有思路..后来直接用了jdbc来实现.这几天不是很忙,所以决定自己再搭建一次.不多说, ...
- SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
前言 本篇文章主要讲述的是SpringBoot整合Mybatis.Druid和PageHelper 并实现多数据源和分页.其中SpringBoot整合Mybatis这块,在之前的的一篇文章中已经讲述了 ...
- springboot+mybatis+druid数据库连接池
参考博客https://blog.csdn.net/liuxiao723846/article/details/80456025 1.先在pom.xml中引入druid依赖包 <!-- 连接池 ...
- SpringBoot+Mybatis+Druid批量更新 multi-statement not allow异常
本文链接:https://blog.csdn.net/weixin_43947588/article/details/90109325 注:该文是本博主记录学习之用,没有太多详细的讲解,敬请谅解! ...
- Springboot+mybatis+druid 配置多数据源
项目结构 application.yml配置文件 spring: application: name: service datasource: primary: jdbc-url: jdbc:orac ...
随机推荐
- 学以致用十-----centos7.2+python3.6+vim8.1+YouCompleteMe
趟过了之前的坑后,再来安装YouCompleteMe 一.安装依赖包 yum install libXt-devel gtk2-devel yum -y install python-devel ru ...
- 20155205 《Java程序设计》实验二(Java面向对象程序设计)实验报告
20155205 <Java程序设计>实验二(Java面向对象程序设计)实验报告 一.实验内容及步骤 (一)单元测试 (1)三种代码 举例:我们要在一个MyUtil类中解决一个百分制成绩转 ...
- 1.8.1suspend与resume方法使用
暂停线程意味着线程还能恢复运行 suspend()方法暂停线程.resume()恢复线程 测试如下 package com.cky.thread; /** * Created by edison on ...
- c语言洗牌算法
#include<stdio.h> #include<stdlib.h> #include<time.h> #include<string.h> voi ...
- 【python-pip】pip安装国外插件timeout解决方案
为什么会timeout呢,你懂得(不懂???!!!) 解决方案: 使用国内豆瓣镜像安装(也有其他的镜像,自己可以搜) pip install xxx -i http://pypi.douban.com ...
- Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏
B. Karen and Coffee time limit per test 2.5 seconds memory limit per test 512 megabytes input standa ...
- 第73讲:Scala界面和事件处理编程进阶实战
今天学习了王家林老师讲解的scala编程的第73讲,主要是文件选择器的使用.让我们通过代码来亲身体验一下. import scala.swing._import java.io.Fileimport ...
- spark的shuffle机制
对于大数据计算框架而言,Shuffle阶段的设计优劣是决定性能好坏的关键因素之一.本文将介绍目前Spark的shuffle实现,并将之与MapReduce进行简单对比.本文的介绍顺序是:shuffle ...
- java基础知识-逻辑运算符
/*首先申明:逻辑运算符的操作数都是布尔型表达式*/ /* 演示逻辑运算符 & :两个操作数都为真的时候结果为真 | :两个操作数只要有一个为真,结果就为真 && :短路与,左 ...
- UNIGUI上传文件
UNIGUI上传文件 uniGUI提供了一个文件上传控件TUniFileUpload,进行数据的导入就变得比较容易.首先将TUniFileUpload控件放置在窗体上,按下导入按钮后,执行TUniFi ...