public <t>list<t> query(simplequery simplequery,pager pager, rowmapper<t> rowmapper){ string querysql = simplequery.getquerysql(); object args = simplequery.getargs(); long count = count(simplequery); pager.settotalobjects(count); if(count<=pager.getfirstresult()){ return new arraylist<t>(); } string pagingquerysql = createpagingquerysql(querysql, pager.getfirstresult(), pager.getpagesize()); if(args == null){ return jdbctemplate.query(pagingquerysql, rowmapper); }else{ return jdbctemplate.query(pagingquerysql, rowmapper, args); } } public list <map<string,object>> query(simplequery simplequery,pager pager){ string querysql = simplequery.getquerysql(); object args = simplequery.getargs(); long count = count(simplequery); pager.settotalobjects(count); if(count<=pager.getfirstresult()){ return new arraylist<map<string,object>>(); } string pagingquerysql = createpagingquerysql(querysql, pager.getfirstresult(), pager.getpagesize()); if(args == null){ return jdbctemplate.queryforlist(pagingquerysql); }else{ return jdbctemplate.queryforlist(pagingquerysql, args); } }
接上回:
在对象村的春天公司里,大家讨论着:
添加这个功能,应该很简单...
恩,只要复制粘贴一下,然后引入rowmapper,很快就完成了这个功能...
但是这样就产生了重复代码...
看来原来的设计是存在问题的,通过这次添加功能,这个问题暴露了出来...
那么,准备开始重构吧...