MyBatis动态SQL,含分页功能
1. 写一个SqlProvider类: public class DynamicSql { public String sql(String sql){ return sql; } } 2. 写一个Mapper类: @Mapper public interface DynamicMapper { @SelectProvider(type=DynamicSql.class, method = "sql") List< HashMap<String,Object>> get(String sql); } 3. 使用实例: List< HashMap<String,Object>> clients = dynamicMapper.get(" SELECT * FROM client"); 4. 带分页功能: PageHelper.startPage(1, 10); List< HashMap<String,Object>> clients = dynamicMapper.get(" SELECT * FROM client"); return AjaxResult.success( new PageInfo(clients)); //此行按需求灵活处理 来源: oschina 链接: https://my.oschina.net/u/4006447/blog/3215512