2019-1-10记一次尝试写需求失败笔记

关于Mybatis的笔记记录

Mybatis的xml数据库映射关系

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.orochi.manager.dal.dao.model.helloWorldMapext">
<resultMap id="helloWorldMap" type="com.orochi.manager.dal.model.helloWorldPo">
<id column="id" property="id" jdbcType="BIGINT" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="room_id" property="roomId" jdbcType="VARCHAR" />
<result column="date_created" property="dateCreated" jdbcType="TIMESTAMP" />
<result column="date_without_time" property="dateWithoutTime" jdbcType="DATE" />
</resultMap>

<selsect id="getHelloWorldList" resultMap="helloWorldMap" parameterType="com.orochi.manager.dal.model.dto.helloWorldDto">
SELECT a.id,
a.id,
b.name,
b.room_id,
c.date_created,
c.date_without_time
FROM recharge_record as a
inner join safety_campus.user as b on [CONDITION]
inner join goods_price as c on [CONDITION]
inner join user_vip_info as d on [CONDITION]
</select>
<if test="id">
[CONDITION]
</if>
</mapper>

通过分析上述的xml代码可以看出
id ==> id
name ==> name
room_id ==> roomId
date_created ==> dateCreated
date_without_time ==> dateWithoutTime

数据库的字段中的字段 你的实体类中的参数 映射的数据类型
id id BIGINT
name name VARCHAR
room_id roomId BIGINT
date_created dateCreated TIMESTAMP^[TIMESTAMP 传送的主要拥有年月日和时分秒的时间戳]
date_without_time dateWithoutTime DATE^[DATE 传送的主要是年月日 没有时分秒]

有关Java和Mysql数据类型对应关系表

类型名称 显示长度 数据库数据类型 Java类型
VARCHAR L+N VARCHAR java.lang.String
CHAR N CHAR java.lang.String
BLOB L+N BLOB java.lang.byte[]
TEXT 65535 VARCHAR java.lang.String
INTEGER 4 INTEGER UNSIGNED java.lang.Long
TINYINT 3 TINYINT UNSIGNED java.lang.Integer
SMALLINT 5 SMALLINT UNSIGNED java.lang.Integer
MEDIUMINT 8 MEDIUMINT UNSIGNED java.lang.Integer
BIT 1 BIT java.lang.Boolean
BIGINT 20 BIGINT UNSIGNED java.math.BigInteger
FLOAT 4+8 FLOAT java.lang.Float
DOUBLE 22 DOUBLE java.lang.Double
DECIMAL 11 DECIMAL java.math.BigDecimal
BOOLEAN 1 同TINYINT 同TINYINT
ID 11 PK (INTEGER UNSIGNED) java.lang.Long
DATE 10 DATE java.sql.Date
TIME 8 TIME java.sql.Time
DATETIME 19 DATETIME java.sql.Timestamp
TIMESTAMP 19 TIMESTAMP java.sql.Timestamp
YEAR 4 YEAR java.sql.Date

有关于INNER JOIN 、RIGHT JOIN 和 LEFT JOIN的比较

如图^[借用来自stackoverflow一大佬的回复插图 https://stackoverflow.com/questions/5706437/whats-the-difference-between-inner-join-left-join-right-join-and-full-join]

具体详细介绍可以参考 https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

有关于MYSQL函数大全及用法示例 具体的可以参考 https://www.cnblogs.com/xuyulin/p/5468102.html这篇博文