闲杂小记(l六)


图记、精选、宝宝标签、家庭共享接口实现:



收获:

1:不需要的字段尽量不要写在请求数据类型或者应答数据类型中


2:如果不能穿null,则能使用基本数据类型的尽量使用数据类型


3:编辑时可用考虑不修改的字段传null,表示不修改改字段


4:String类型字段的需要校验最大长度

if (userID < 1L
        || params == null
        || StringUtils.isBlank(params.getCoverImgPath())
        || StringUtils.isBlank(params.getTitle())
        || (null!=params.getCoverImgPath()&&params.getCoverImgPath().length()>128)  TODO: 16/8/22
        || (null!=params.getTitle()&&params.getTitle().length()>14)
        || (null!=params.getDescription()&&params.getDescription().length()>108)) {
    throw new IllegalArgumentException("checkDeleteGrowUpInfoParams fail!");
}

5:数组也可以使用增强for遍历

long[] addPids = editAlbumParam.getAddPids();
        //如果需要添加图片就添加图记与图片的关系
        if (null != addPids && addPids.length >= 1L) { TODO: 16/8/18 DONE
            //添加图片与图记的关系
            for (long pid : addPids) {
//                Long pid = addPids[i];
                //建立图记与图片关系
                AlbumPictureRelation albumPictureRelation = generateAlbumPictureRelation(aid, pid);
                albumPictureRelationMapper.insert(albumPictureRelation);
            }
6:delete使用别名时需要在delete 后面也加同一别名

 <delete id="deleteBabyTag">
  delete bt from baby_tag as bt
  where  bt.entity_id= #{entityId,jdbcType=BIGINT}
  AND bt.baby_id=#{babyId,jdbcType=BIGINT}
  AND bt.entity_type=#{entityType,jdbcType=INTEGER}
</delete>
7:可以在注解中写入名字加以区分

@Controller("newAlbumController")
//    @Controller
@RequestMapping("/api/v2/album")
public class AlbumController {

@Qualifier("newAlbumMapper")
private AlbumMapper albumMapper;
8:mapper重名,扫描多个包时配置

<!-- sessionFactory 将spring和mybatis整合 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:sqlMapConfig.xml" />
    <!--<property name="mapperLocations" value="classpath:main/java/**/*.xml,com/ibbpp/api/mapper/*.xml" />    &lt;!&ndash; 加载mapper文件 &ndash;&gt;-->
    <property name="mapperLocations" value="classpath:**/mapper/*Mapper.xml" />
</bean>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值