spring boot学习第二天-配置连接并输出
在application.yaml配置数据的连接地址
server: port: 8003 spring: datasource: url: jdbc:mysql://localhost:3306/teaching?serverTimezone=GMT%2b8 username: root password: 123456 # type: com.alibaba.druid.pool.DruidDataSource mybatis-plus: global-config: db-config: logic-delete-field: del_flag logic-not-delete-value: 0 logic-delete-value: 2 configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 在test里面添加测试类
void testMyBatis(){ QueryWrapper<StudentInfo> wrapper =new QueryWrapper<>(); List<StudentInfo> info=studentDao.selectList(wrapper); for (StudentInfo student:info){ System.out.println(student.getStuiName()); } } 在entiy配置数据库的访问字段
public class StudentInfo { private Long stuiId; //BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键', private String stuiName; //VARCHAR(50) NOT NULL DEFAULT '' COMMENT '学生姓名' COLLATE 'utf8mb4_general_ci', private Integer stuiAge; //TINYINT(2) NOT NULL DEFAULT '0' COMMENT '学生年龄', private Integer stuiGender; //TINYINT(2) NULL DEFAULT '0' COMMENT '性别', private String stuiSid; //VARCHAR(20) NOT NULL DEFAULT '' COMMENT '学生学号' COLLATE 'utf8mb4_general_ci', private String stuiAcademy; //VARCHAR(50) NULL DEFAULT '' COMMENT '所属学院' COLLATE 'utf8mb4_general_ci', private String stuiSpecialized; //VARCHAR(50) NULL DEFAULT '' COMMENT '专业' COLLATE 'utf8mb4_general_ci', private String stuiGrade; //VARCHAR(20) NOT NULL DEFAULT '' COMMENT '年级' COLLATE 'utf8mb4_general_ci', // private Integer stuiClass; //TINYINT(2) NULL DEFAULT '0' COMMENT '班级', private String stuiIdCard; //VARCHAR(20) NULL DEFAULT '' COMMENT '身份证号' COLLATE 'utf8mb4_general_ci', private String stuiPhone; //VARCHAR(20) NOT NULL DEFAULT '' COMMENT '电话号码' COLLATE 'utf8mb4_general_ci', private Integer stuiStatus; //TINYINT(2) NOT NULL DEFAULT '0' COMMENT '学生状态\r\n0:在校学习\r\n7:服兵役\r\n8:已毕业\r\n9:休学', private Timestamp stuiCtTime; //TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间', private Timestamp stuiUpTime; //TIMESTAMP NULL DEFAULT NULL COMMENT '记录修改时间', } 运行就能看到输出内容
本文系作者 @2374579255 原创发布在 萌博客。未经许可,禁止转载。