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)); //此行按需求灵活处理

 

以上是 MyBatis动态SQL,含分页功能 的全部内容, 来源链接: utcz.com/z/514965.html

回到顶部