MyBatis-Plus的應用

MyBatis-Plusjava

Author: Lijbmysql

Email: lijb1121@163.comspring

導入依賴sql

<!--springboot父項目-->
	<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath /> 
    </parent>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <skipTests>true</skipTests>
    </properties>


<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <!--mybatis-plus和springboot整合jar-->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.0.7.1</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.44</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.9</version>
    </dependency>

</dependencies>

配置SpringBoot的yml文件數據庫

server:
  port: 8088
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      url: jdbc:mysql://***.***.*.***:3306/*?useUnicode=true&characterEncoding=utf8&useSSL=false #數據庫訪問地址
      username: ***
      password: ***
      driver-class-name: com.mysql.jdbc.Driver

Beanspringboot

package com.neunn.bean;

import lombok.Data;
import java.util.Date;

/**
 * [@author](https://my.oschina.net/arthor) lijb
 * [@company](https://my.oschina.net/u/3478402) 東網
 * [@date](https://my.oschina.net/u/2504391) 2019/1/16  13:46
 */
[@Data](https://my.oschina.net/difrik)
public class MybatisPlusTest {
    private String uuid;
    private String name;
    private Integer age;
    private Date bir;

}

Mapper(DAO)mybatis

package com.neunn.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neunn.bean.MybatisPlusTest;

/**
 * @author lijb
 * @company 東網
 * @date 2019/1/16  13:48
 */
public interface MybatisPlusTestMapper  extends BaseMapper<MybatisPlusTest> {

}

Testapp

package com.neunn.test;

import com.neunn.bean.MybatisPlusTest;
import com.neunn.dao.MybatisPlusTestMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author lijb
 * @company 東網
 * @date 2019/1/16  13:50
 */

@RunWith(SpringRunner.class)
@SpringBootTest
public class TestMyBatisPlus {

    @Autowired
    private MybatisPlusTestMapper myDao;

    @Test
    public void testQuery(){
        List<MybatisPlusTest> list = myDao.selectList(null);
        System.out.println(list.toString());
    }

}

測試結果spring-boot

[MybatisPlusTest(uuid=1, name=ljb, age=18, bir=Wed Jan 16 13:53:51 GMT+08:00 2019)]
相關文章
相關標籤/搜索