mybatis_mapper.xml文件参考

parameterTyp=int、string、long、Date;

 

表中的列与java属性对应关系

<resultMap id="order" type="com.cmiinv.shp.model.generated.TOrder">
  <id column="id" jdbcType="BIGINT" property="id"/> <!--java Long--->
  <result column="count" jdbcType="INTEGER" property="count"/> <!--java Integer--->
  <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>    <!--java String--->
  <result column="state" jdbcType="CHAR" property="state"/> <!--java String--->
  <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/> <!--java Date--->
  <!--LONGVARCHAR实际对应数据库中的longtext(或者text)-->
  <result column="describe_text" jdbcType="LONGVARCHAR" property="describeText"/> <!--java String--->
</resultMap>

< 小于号是要转码的 &gt;
foreach用法

where id in
<foreach collection="xxxList" item="xxx" open="(" separator="," close=")">
    #{xxx}
</foreach>
if test
<if test="xxxList != null and xxxList.size() > 0">
</if>
<if test="targetState == @com.cmiinv.shp.model.order.OrderState@CONFIRMED.code">
   confirm_time = now()
</if>
choose when otherwise

<choose>
  <when test="states != null and states.size() > 0">
      xxxsqlxxx
  </when>
  <otherwise>
     xxxsqlxxx
  </otherwise>
</choose>


like

时间

select * from t_goods 
where create_time &gt; now();

状态引用枚举

and go.state = '${@com.cmiinv.shp.model.order.GroupOrderState@JOINABLE.code}'

按条件查询

<!--按条件查询-->
<select id="findByProduccategoryModel" parameterType="sers.lenovo.Desktop.test.ProduccategoryModel" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_product_category where 1=1
    <if test="parentId != null">
    	and parent_id=#{parentId,jdbcType=BIGINT}
    </if>
    <if test="code != null">
    	and code=#{code,jdbcType=CHAR}
    </if>
</select>

count(*)查询 

java代码为  
long findopenGroupOrderCount(Long groupProductId);

<select id="findopenGroupOrderCount" resultType="long" parameterType="long">
        select count(*) from t_group_order where group_product_id=#{groupProductId,jdbcType=BIGINT};
</select> 

update修改

javaMapper的代码
int updateProductSkuStock(@Param("productId") Long productId, 
@Param("skuCode") String skuCode, 
,@Param("orderCount") Integer orderCount);

Mapper.xml
<update id="updateProductSkuStock">
  update t_product_sku
  set stock = stock + #{orderCount}, order_stock = order_stock - #{orderCount}
  where product_id=#{productId,jdbcType=BIGINT} and sku_code=#{skuCode,jdbcType=VARCHAR} and order_stock>=#{orderCount}
</update>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值