mybatis(7)使用经验
@Param的使用
Java代码中指定@Param("model"),mapper.xml配置中也需要
List<ProductInfo> queryByPage(@Param("model") ProductQueryReq queryModel);
<select id="queryByPage" resultMap="BaseResultMap"> select
<include refid="Base_Column_List" />
from product_info
where is_deleted="N"
<if test= "model.productStatus != null">
and status = #{model.productStatus,jdbcType=INTEGER}
</if>
</select>
mapper.xml中不写则启动报错:
BoundSql.getParameterObject():
只有一个参数可以不指定@Param, 且mapper.xml中可直接用对象属性
List<ProductInfo> queryByPage(ProductQueryReq queryModel);
如果mapper.xml用了别名报错:
有多个相同类型参数也需要定义@Param
UserImageTransfer selectFirstHistoryOrcInfo(String productCode, String userId);
collection的用法
collection 下 主表 和附表 都需要查出主键;即使<id>标签写了其他字段也没用,一定是数据库表真实的主键.
<resultMap id="BaseResultMap" type="com.noob.domain.CmbClaimPackage" > <id column="id" property="id" jdbcType="BIGINT" />
<result column="batch_no" property="batchNo" jdbcType="VARCHAR" />
<result column="product_code" property="productCode" jdbcType="VARCHAR" />
<result column="package_no" property="packageNo" jdbcType="VARCHAR" />
<result column="serial_no" property="serialNo" jdbcType="VARCHAR" />
<result column="amount" property="amount" jdbcType="DECIMAL" />
<result column="total_count" property="totalCount" jdbcType="DECIMAL" />
<result column="origin_info" property="originInfo" jdbcType="VARCHAR" />
<result column="trade_status" property="tradeStatus" jdbcType="INTEGER" />
<result column="return_info" property="returnInfo" jdbcType="VARCHAR" />
<result column="upload_sign" property="uploadSign" jdbcType="CHAR" />
<result column="last_upload_date" property="lastUploadDate" jdbcType="VARCHAR" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="creator" property="creator" jdbcType="VARCHAR" />
<result column="gmt_created" property="gmtCreated" jdbcType="TIMESTAMP" />
<result column="modifier" property="modifier" jdbcType="VARCHAR" />
<result column="gmt_modified" property="gmtModified" jdbcType="TIMESTAMP" />
<result column="is_deleted" property="isDeleted" jdbcType="CHAR" />
</resultMap>
<resultMap id="PackageModelResultMap" type="com.noob.model.CmbClaimPackageModel" extends="BaseResultMap">
<collection property="detailList" javaType="list" ofType="com.noob.domain.CmbClaimDetail">
<id column="d_id" property="id" jdbcType="BIGINT" />
<result column="d_batch_no" property="batchNo" jdbcType="VARCHAR" />
<result column="d_product_code" property="productCode" jdbcType="VARCHAR" />
<result column="d_amount" property="amount" jdbcType="DECIMAL" />
<result column="d_package_no" property="packageNo" jdbcType="VARCHAR" />
<result column="d_contract_no" property="contractNo" jdbcType="VARCHAR" />
<result column="d_policy_no" property="policyNo" jdbcType="VARCHAR" />
<result column="d_serial_no" property="serialNo" jdbcType="VARCHAR" />
<result column="d_trade_no" property="tradeNo" jdbcType="VARCHAR" />
<result column="d_report_amount" property="reportAmt" jdbcType="DECIMAL" />
<result column="d_trade_status" property="tradeStatus" jdbcType="INTEGER" />
<result column="d_resp_code" property="respCode" jdbcType="VARCHAR" />
<result column="d_resp_msg" property="respMsg" jdbcType="VARCHAR" />
<result column="d_report_no" property="reportNo" jdbcType="VARCHAR" />
<result column="d_claim_no" property="claimNo" jdbcType="VARCHAR" />
<result column="d_return_info" property="returnInfo" jdbcType="VARCHAR" />
<result column="d_agreed_repay_date" property="agreedRepayDate" jdbcType="VARCHAR" />
<result column="d_gmt_created" property="gmtCreated" jdbcType="TIMESTAMP" />
</collection>
</resultMap>
<select id="selectDoing" resultMap="PackageModelResultMap" parameterType="java.util.Date" >
select p.id,
p.batch_no,
p.serial_no,
p.product_code,
p.package_no,
p.amount,
p.origin_info,
p.trade_status,
p.return_info,
d.id d_id,
d.product_code d_product_code,
d.package_no d_package_no,
d.batch_no d_batch_no,
d.serial_no d_serial_no,
d.amount d_amount,
d.contract_no d_contract_no,
d.policy_no d_policy_no,
d.trade_no d_trade_no,
d.report_amount d_report_amount,
d.trade_status d_trade_status,
d.resp_code d_resp_code,
d.resp_msg d_resp_msg,
d.report_no d_report_no,
d.claim_no d_claim_no,
d.agreed_repay_date d_agreed_repay_date,
d.gmt_created d_gmt_created,
d.return_info d_return_info
from cmb_creditcard_claim_package p inner join cmb_creditcard_claim_detail d on p.batch_no = d.batch_no
where p.gmt_created >= #{beginDate,jdbcType=TIMESTAMP}
and <include refid="doing_condition"/>
and <include refid="alive_condition"/>
</select>
以上是 mybatis(7)使用经验 的全部内容, 来源链接: utcz.com/z/510306.html