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>
< 小于号是要转码的 >
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 > 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>