mybatis多参数传入的动态sql

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 t_sys_news SET
        
            is_delete = 1
        
        
            state = 2
        
        where news_id = #{0}
    

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}表示第二位参数,以此类推

判断中 param1代表第一位参数,param2代表第二位参数,以此类推

你可能感兴趣的:(Mybatis知识点)