常见代码

一、判空操作

1.字符串判空

StringUtil.isBlank("") ;

2.集合判空

CollectionUtils.isEmpty(businessRegisters)

二、代码中常量处理

1.公共常量

添加到  common-util 中 UserConstant.java  或 com.dhgate.ywuser.util.Constants.java

2.临时常量

/**
* 产品注册品牌证书:允许添加的最大数量5
*/
private static final Integer BUSINESS_REGISTER_CERTIFICATION_COUNT = 5;

3.最终目的

代码中不要出现数字,或含义不明确的地方

三、页面代码

1.使用parse 标签,抽取出公共部分,减少代码维护量

四、数据操作

1.若同时对多个数据表进行操作,使用事务

参考代码:买家审核——审核操作,订单

原理:重新定义一个接口,接口实现使用transactional 标签

      在接口实现中将多个数据表的操作放在同一个实现中,要抛出异常,有异常发生时操作自动回滚,不会出现脏数据

五、修复  列表页面查询时 若不在首页进行搜索,查询不到结果的问题
<input type="submit" value="搜索" class="btn-input j-productSub" onclick="initPage();"></input>
<script>

function initPage(){
jQuery("#page").val(1);
}

六、获取VM中集合的首项  以及  判断集合是否为空

#if($!finMain.productNames.size() >0 )
    #set($product = $!finMain.productNames.get(0))
    <a href="$base/prd/productmanage/prdview.do?productid=$product.productId&sid=$!finMain.proMerchantId" target="_blank">
    #cutoff($product.productName)
    </a>
#else

#end


七、Mapper 中  循环遍历代码
<if test="parameter.uids != null">
and (uid in
<foreach collection="parameter.uids" index="index"
item="item" open="(" separator="," close=")">
#{parameter.uids[${index}],jdbcType=BIGINT}
</foreach>
)
</if>

猜你喜欢

转载自mingyundezuoan.iteye.com/blog/2289699