Mybatis学习记录

Mybatis 使用记录

1.需要加的依赖在此忽略
2.Mybatis的核心配置:
在这里插入图片描述
Mapper.xml内容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<resultMap id="BaseResultMap" type="com.example.springbootdemo.sql.model.PilotUserAccess">
    <id column = "CUSTOMER_ID" property="customerId" jdbcType="VARCHAR"/>
    <result column="USER_ID" property="userId" jdbcType="VARCHAR"/>
    <result column="USER_TPID" property="userTpid" jdbcType="VARCHAR"/>
    <result column="PRODUCT_NAME" property="productName" jdbcType="VARCHAR"/>
</resultMap>

<sql id="Base_Column_List">
    CUSTOMER_ID,USER_ID,USER_TPID,PRODUCT_NAME
</sql>

<select id="queryPilotUserInfoByMapper" resultMap="BaseResultMap" parameterType="java.lang.String" resultType="com.example.springbootdemo.sql.model.PilotUserAccess">
    select <include refid="Base_Column_List"/> from PILOT_USER_ACCESS where CUSTOMER_ID = #{customerId}
</select>

resultMap=“BaseResultMap” 这个属性是重点,不能缺少,否则查询出来的数据是null.

<result…/>标签里的column值大小写无所谓…

application.yml配置文件里关于Mybatis的配置只需要如下的配置即可,别整其他没用的
mybatis:
mapper-locations: classpath:Mapper/*.xml

@Mapper注解标注的接口如下:
@Mapper
public interface PilotUserAccessMapper
{
// @Select(“select * from PILOT_USER_ACCESS where customer_Id = #{customerId}”)
PilotUserAccess queryPilotUserInfoByMapper( String customerId);
}

实体类:
@Entity
public class PilotUserAccess
{
private String userId;

private String userTpid;

@Id
private String customerId;

private String productName;

public String getUserId()
{
    return userId;
}

public void setUserId(String userId)
{
    this.userId = userId;
}

public String getUserTpid()
{
    return userTpid;
}

public void setUserTpid(String userTpid)
{
    this.userTpid = userTpid;
}

public String getCustomerId()
{
    return customerId;
}

public void setCustomerId(String customerId)
{
    this.customerId = customerId;
}

public String getProductName()
{
    return productName;
}

public void setProductName(String productName)
{
    this.productName = productName;
}

}

其他内容不需要记录,应该都知道。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值