review
之前的比较分散,自己用。。。
sql脚本
-- auto-generated definition
create table stu_info
(
stu_id int auto_increment
primary key,
stu_name varchar(255) null,
stu_age int(255) null,
stu_gender varchar(4) null,
stu_birth date null
);
实体类
package cn.bitqian.entity;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author echo lovely
* @date 2020年11月16日 下午7:13:32
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StuInfo {
private Integer stuId;
private String stuName;
private Integer stuAge;
private String stuGender;
private Date stuBirth;
}
sql watch out
<?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="cn.bitqian.mapper.StuInfoMapper">
<resultMap id="stuInfoMap" type="StuInfo">
<id property="stuId" column="stu_id" />
<result property="stuName" column="stu_name" />
<result property="stuAge" column="stu_age" />
<result property="stuGender" column="stu_gender" />
<result property="stuBirth" column="stu_birth" />
</resultMap>
<!-- 使用 <![CDATA[ sql ]]> 转义 -->
<!-- select * from stu_info where stu_age <![CDATA[ < ]]> #{stuAge} -->
<select id="getStuInfoByAge" parameterType="int" resultMap="stuInfoMap">
<![CDATA[
select * from stu_info where stu_age < #{stuAge}
]]>
</select>
<!-- sql片段抽取 -->
<sql id="stu_common"> select * from stu_info </sql>
<!-- 模糊查询1 拼接好的参数 -->
<select id="getStuInfoByName1" parameterType="string" resultMap="stuInfoMap">
<include refid="stu_common" />
where stu_name like #{stuName}
</select>
<!-- 模糊查询2 直接给参数 ${} -->
<select id="getStuInfoByName2" parameterType="string" resultMa