MyBatis初级实战之五:一对一关联查询,linux操作系统实用教程文东戈课后答案

id int(32) NOT NULL AUTO_INCREMENT,

name varchar(32) NOT NULL,

age int(32) NOT NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS log;

CREATE TABLE log (

id int(32) NOT NULL AUTO_INCREMENT,

user_id int(32),

action varchar(255) NOT NULL,

create_time datetime not null,

PRIMARY KEY (id)

) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

INSERT INTO mybatis.user (id, name, age) VALUES (3, ‘tom’, 11);

INSERT INTO mybatis.log (id, user_id, action, create_time) VALUES (3, 3, ‘read book’, ‘2020-08-07 08:18:16’);

INSERT INTO mybatis.log (id, user_id, action, create_time) VALUES (4, 3, ‘go to the cinema’, ‘2020-09-02 20:00:00’);

INSERT INTO mybatis.log (id, user_id, action, create_time) VALUES (5, 3, ‘have a meal’, ‘2020-10-05 12:03:36’);

INSERT INTO mybatis.log (id, user_id, action, create_time) VALUES (6, 3, ‘have a sleep’, ‘2020-10-06 13:00:12’);

INSERT INTO mybatis.log (id, user_id, action, create_time) VALUES (7, 3, ‘write’, ‘2020-10-08 09:21:11’);

本次实战的java工程

  1. 在父工程mybatis下新建子工程relatedoperation,pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=“http://maven.apache.org/POM/4.0.0” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=“http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd”>

4.0.0

com.bolingcavalry

mybatis

1.0-SNAPSHOT

…/pom.xml

com.bolingcavalry

relatedoperation

0.0.1-SNAPSHOT

relatedoperation

Demo project for Mybatis related operation in Spring Boot

<java.version>1.8</java.version>

org.projectlombok

lombok

org.springframework.boot

spring-boot-starter-web

org.mybatis.spring.boot

mybatis-spring-boot-starter

mysql

mysql-connector-java

runtime

org.springframework.boot

spring-boot-starter-test

test

io.springfox

springfox-swagger2

io.springfox

springfox-swagger-ui

com.alibaba

druid-spring-boot-starter

junit

junit

test

org.springframework.boot

spring-boot-maven-plugin

  1. 基本配置文件application.yml:

server:

port: 8080

spring:

#1.JDBC数据源

datasource:

username: root

password: 123456

url: jdbc:mysql://192.168.50.43:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC

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

#2.连接池配置

druid:

#初始化连接池的连接数量 大小,最小,最大

initial-size: 5

min-idle: 5

max-active: 20

#配置获取连接等待超时的时间

max-wait: 60000

#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒

t

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值