闲杂小记(l六)

来源:互联网 发布:php array判断 编辑:程序博客网 时间:2024/03/29 12:58


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



收获:

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
原创粉丝点击