Mybatis Integer类型,如果传入的值为0 被mapper解析为空字符串

版权声明:夏小薇记 https://blog.csdn.net/qq_39584294/article/details/82592291

哇,又哭啦,血泪史啊,为什么我能完好无误的跳进任何一个坑,然后吭叽吭叽半天找不到原因哭唧唧哇~~~!!!!
先来bug代码
impl层

List<BgChapterVO> listChapterVO=new ArrayList<>();
        Map map=new HashMap<>();
        map.put("chapterId", chapter.getChapterId());
        map.put("chapterStatus", chapter.getChapterStatus());
        map.put("auditStatus", chapter.getAuditStatus());
        PageHelper.startPage(chapter.getPage(),chapter.getLimit());
        listChapterVO=courseVOMapper.selectChapter(map);

注意auditStatus这个磨人的小妖精 他是int类型,和前台妹妹约定的是0代表通过,然而自己写的mapper查到的结果是通过和不通过所有的信息,哇,我的天,找了一下午,(这里我承认我这个小白菜找bug 的能力很差)才发现,原来int类型的0会被mapper解析为这个东西: ’ ’ 一个空串。然鹅,我的mapper为了更完善的测试,自己写的盘空是下面介个样纸,导致准确无误的踩到了bug

<if test="auditStatus!=null and auditStatus!='' ">
                and tcourse.audit_status=#{auditStatus}
            </if>

。。。。。。so,吧后面的判断空串这个条件删了就好啦。如下。

<if test="auditStatus!=null ">
                and tcourse.audit_status=#{auditStatus}
            </if>

或者,如果状态少的话还可以这样

<if test="onlineStatus==0 or onlineStatus==1 ">
                and tcourse.online_status=#{onlineStatus}
            </if>

哇,这简单的bug找了一下午,,,学艺不精啊,,哭唧唧

自我检讨ing

猜你喜欢

转载自blog.csdn.net/qq_39584294/article/details/82592291
今日推荐