该文章是Java入门系列的第七章:DBeaver导入sql数据
DBeaver导入sql数据
首先下载一个数据库管理和开发工具,我下的是DBeaver,网上安装教程挺多的,安装配置好之后,项目连接数据库的配置在上一篇文章已经讲过。所以我们只需要右击已经创建的 student_manage 数据库,选择 工具-恢复数据库,下载并导入此sql文件,就会发现数据库下多了一个 student 表,表中也有了几条数据,下一章节我们会使用 MyBatis-Plus 把这些数据查询出来
创建 Student 类
我们在example目录下新建一个Java类,命名为pojo.Student,然后我们查看 student 表的属性,可以看到这个表中包含以下字段并他们的数据类型
然后在Student文件下编写如下代码,字段和字段类型与数据库的保持一致:
package org.example.pojo;
import lombok.Data;
@Data
public class Student {
private long id;
private String number;
private String name;
private int age;
private int chi;
private int math;
private int eng;
}
接下来写映射,还是在example目录下,新建一个Java类,命名为mapper.StudentMapper,编写代码如下:
其中StudentMapper
继承BaseMapper<Student>
package org.example.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.example.pojo.Student;
public interface StudentMapper extends BaseMapper<Student> {
}
写在最后
以上就是DBeaver导入sql数据的内容,下一章节开始使用MyBatis-Plus查询数据