MyBatis-Plus初试锋芒!!!!太强大了!!!

目录

MyBatis-Plus初试锋芒!!!!太强大了!!!

代码:

连接数据库的配置文件

pojo包下

dao包下

测试

运行结果

 数据库中的数据


MyBatis-Plus初试锋芒!!!!太强大了!!!

代码:

连接数据库的配置文件

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test # ?serverTimezone=UTC
    username: root
    password: root

pojo包下

package com.dong.domian;

public class User {
    private int userid;
    private String username;
    private String sex;

    @Override
    public String toString() {
        return "User{" +
                "userid=" + userid +
                ", username='" + username + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }

    public int getUserid() {
        return userid;
    }

    public void setUserid(int userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }
}

dao包下

package com.dong.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dong.domian.User;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface UserDao extends BaseMapper {
}

测试

package com.dong;

import com.dong.dao.UserDao;
import com.dong.domian.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

@SpringBootTest
class MybatisPlus01QuikstartApplicationTests {

    @Autowired
    private UserDao userDao;
    @Test
    void testGetAll() {
        List users = userDao.selectList(null);
        System.out.println(users);
    }

}

运行结果

MyBatis-Plus初试锋芒!!!!太强大了!!!_第1张图片

 数据库中的数据

MyBatis-Plus初试锋芒!!!!太强大了!!!_第2张图片

 

你可能感兴趣的:(spring学习记录,平时学习,数据库学习,mybatis,oracle,数据库)