Mybatis执行带有动态标签的sql语句

场景:sql由模板配置动态传参进来,并且要支持动态标签的sql

/**
 * 报表Mapper
 *
 * @author Yangqi.Pang
 */
public interface ReportMapper {

    /**
     * select
     *
     * @param sql      sql
     * @param fieldMap fieldMap
     * @return List<JSONObject>
     */
    @SelectProvider(type = SqlProvider.class, method = "buildSql")
    List<JSONObject> query(@Param("sql") String sql, @Param("param") Map<String, Object> fieldMap);

    class SqlProvider {
        public String buildSql(Map<String, Object> map) {
            return "<script>" + map.get("sql") + "</script>";
        }
    }

}
posted @ 2022-04-22 18:35  左手程序,右手诗  阅读(73)  评论(0编辑  收藏  举报