mysql通用mapper_mybatis - 通用mapper

title: 玩转spring-boot-mybatis

date: 2019-03-11 19:36:57

type: "mybatis"

categories: mybatis #分类名

tags: mybatis

---

作为持久层的ORM框架,目前在国内主流之一就是MyBatis,学会用它,用好它肯定是必备的功课

我会主要从下面几个方面入整理本篇博客

快速搭建快发环境

常见的注解

怎么玩?

一. 快速搭建开发环境#

小插曲,添加测试模块的时候,引入junit模块和spring-boot-text-starter模块有先顺序,不然ide会报错...

坐标

Copy

org.springframework.boot

spring-boot-starter-parent

2.0.4.RELEASE

1.8

org.springframework.boot

spring-boot-starter-web

org.mybatis.spring.boot

mybatis-spring-boot-starter

1.3.2

tk.mybatis

mapper-spring-boot-starter

2.0.3

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.5

mysql

mysql-connector-java

8.0.11

junit

junit

text

org.springframework.boot

spring-boot-starter-test

test

org.projectlombok

lombok

另外插一嘴---mysql连接的版本适配

我现在用的云主机docker上的官方版mysql,版本比较新,因此我的调整版本到 8以上,不然会报错说什么

Copy

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could

配置文件:

主要是配置数据库的连接,如果我们使用的是通用mapper,Mybatis可以做到零配置

Copy

server:

port: 8089

spring:

application:

name: text-mybatis

datasource:

url: jdbc:mysql://211.159.XXX.XXX:8888/changwu?serverTimezone=UTC&useUnijava=true&characterEncoding=utf-8&useSSL=false

username: root

password: 2424zcw..

driver-class-name: com.mysql.jdbc.Driver

#输出sql

mybatis:

configuration:

log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

启动类

在这里告诉通用mapper我们的mapper包路径

Copy

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import tk.mybatis.spring.annotation.MapperScan;

@SpringBootApplication

@MapperScan("com.changwu.mapper")

public class MybatisApp {

public static void main(String[] args) {

SpringApplicat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值