Mybatis 使用记录
1.需要加的依赖在此忽略
2.Mybatis的核心配置:
Mapper.xml内容如下:
<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;
}
}
其他内容不需要记录,应该都知道。