jdbctemplate sql的形式查询(结合mysql)

/**
     * 普查模板列表
     * @param isPublish 状态
     * @param templateName 模板名称
     * @param publishTime 发布时间
     * @return
     */
    @GetMapping("list")
    public Res list(String isPublish, String templateName, String publishTime, int pageIndex, int pageSize){
        StringBuilder sb = new StringBuilder(200);
        sb.append("select * from pr_census_template where is_deleted = 0 ");
        Map params = new HashMap<>();
        if(StringUtils.isNotBlank(isPublish)){
            sb.append("and is_publish = :isPublish");
            params.put("isPublish", Integer.valueOf(isPublish));
        }
        if(StringUtils.isNotBlank(templateName)){
            sb.append("and template_name = :templateName ");
            params.put("templateName", templateName);
        }
        if(StringUtils.isNotBlank(publishTime)){
            sb.append("and DATE_FORMAT(last_update_time,'%Y-%m-%d') = :publishTime ");
            params.put("publishTime", publishTime);
        }
        PagedResult pagedResult = queryForPagination(sb, params, pageIndex, pageSize);
        return Res.Success(pagedResult,"查询成功");
    }

 

你可能感兴趣的:(MySql,java)