mybatis多参数传入的动态sql

来源:互联网 发布:ubuntu安装libapu 编辑:程序博客网 时间:2024/06/05 07:47

mybatis参数传入,不用map与实体类封装,直接传入

1.service层

@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)    public int update(String newsId, int type) {        return sysNewsRedoMapper.update(newsId,type);    }

2.mapper文件

<update id="update">        update t_sys_news SET        <if test="param2 == 0">            is_delete = 1        </if>        <if test="param2 == 1">            state = 2        </if>        where news_id = #{0}    </update>

3.controller层

@ApiOperation("删除与下架接口")    @PostMapping("/update")    @ApiImplicitParams({            @ApiImplicitParam(paramType = "query", name = "newsId", dataType = "String", required = true, value = "新闻媒体主键"),            @ApiImplicitParam(paramType = "query", name = "type", dataType = "int", required = true, value = "操作类型 0删除 1下架")    })    public Map update(@RequestParam(value = "newsId") String newsId,                      @RequestParam(value = "type") int type){

注:

#{0}表示第一位参数,#{2}表示第二位参数,以此类推

<if test="">判断中 param1代表第一位参数,param2代表第二位参数,以此类推

原创粉丝点击