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 ...
随机推荐
- 时间控件My97简单用法
my97的用法很是简单,项目中用到,查了资料才找到的,简单使用,记一下,方便查阅. 1.添加依赖. <script language="javascript" type=&q ...
- 微信小程序之弹框modal
官方文档 <modal hidden="{{hidden}}" title="这里是title" confirm-text="自定义确定按钮&q ...
- Spring通过注解配置Bean
@Component: 基本注解, 标识了一个受 Spring 管理的组件@Repository: 标识持久层组件@Service: 标识服务层(业务层)组件@Controller: 标识表现层组件 ...
- redis简单使用
主要参考资料:http://wiki.jikexueyuan.com/project/redis-guide/data-type.html一.redis 安装1.在官网下载安装包2.解压安装包 tar ...
- python生成器实例
生成器是一种特殊的迭代器,它有yield语句 #coding:utf-8def fibs(max): n,a,b = 0,0,1 while n < max: yield b a , b = b ...
- vc6中向vs2010迁移的几个问题(2)
1. 库文件的迁移 参考:http://www.cnblogs.com/icmzn/p/6724969.html 2. 其他项目中的可能遇到的问题: 2.1 无法打开包括文件:“fstream.h”: ...
- [leetcode 14]Longest Common Prfix
1 题目: Write a function to find the longest common prefix string amongst an array of strings. Hide Ta ...
- 使用ActionFilterAttribute实现MVC后台授权
授权就是我们在用户未登录的情况下不允许访问一些页面,只有登录后才能进行访问一些页面. 在mvc中我们可以使用ActionFilterAttribute来进行授权验证来阻止一些未经授权的直接访问的页面. ...
- 在ASP.NET MVC部署AngularJs
创建一个ASP.NET MVC项目. 打开NuGet管理,安装angularjs: 在App_Start目录下,Bundle刚刚安装的angularjs库: 在Global.asax.cs的Appli ...
- 改变您的HTTP服务器的缺省banner
(以下方法仅针对 IIS Asp.net) 服务器扫描发现漏洞,其中一个是: 可通过HTTP获取远端WWW服务信息 [Microsoft-IIS/8.5] 漏洞描述 本插件检测远端HTTP Serve ...