mybatis_mapper.xml文件参考

表中的列与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>

按条件查询

<!--按条件查询-->
<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>

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/82925370