首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

分开valuelist的sql拼装

2013-11-29 
分离valuelist的sql拼装这几天用的sql的动态拼装,一下子就想到的valuelist,但是valuelist有好多前端的东西

分离valuelist的sql拼装
这几天用的sql的动态拼装,一下子就想到的valuelist,但是valuelist有好多前端的东西我们又用不到,所以想了想决定吧valuelist的动态拼装提出来。直接上传源码,不喜勿喷!

<bean id="hibernate4Adapter" ref="entityManagerFactory" />
    //hibernate的
<property name="sessionFactoryBean" ref="sessionFactoryBean" />
</bean>

<bean id="columnMapRowMapper" />
<bean id="sqlPagingSupport" />

<bean id="jdbcAdapter" >
<property name="showSql" value="${hibernate.showSql}" />
<property name="dataSource" ref="dataSource" />
<property name="rowMapper" ref="columnMapRowMapper" />
<property name="sqlPagingSupport" ref="sqlPagingSupport" />
</bean>
  //这个配置文件必须有
  ${hibernate.dialect}
 
 

    @Autowiredpublic Hibernate4Adapter hibernate4Adapter;@Autowiredprivate JdbcAdapter jdbcAdapter;@Testpublic void jdbc(){try {String sql = "select * from inspur_topic where 1=1 " +"/~name: and name = {name}~/" +"/~name: and name = '[name]'~/" +"/~sortColumn: order by [sortColumn] [sortDirection]~/";HashMap filters = new HashMap();filters.put("sortColumn", "id");filters.put("pagingNumberPer", "2");filters.put("sortDirection", "desc");filters.put("pagingPage", "1");filters.put("name", "新闻");net.mlw.vlh.ValueListInfo info = new net.mlw.vlh.ValueListInfo(filters);ValueList valueList = jdbcAdapter.getValueList(sql, info);System.err.println(valueList.getList().size());     } catch (Exception e) {e.printStackTrace();}}      @Testpublic void hibernate(){try {String hql = "from topic where 1=1 " +"/~name: and name = {name}~/" +"/~name: and name = '[name]'~/" +"/~sortColumn: order by [sortColumn] [sortDirection]~/";HashMap filters = new HashMap();filters.put("sortColumn", "id");filters.put("pagingNumberPer", "2");filters.put("sortDirection", "desc");filters.put("pagingPage", "1");filters.put("name", "新闻");net.mlw.vlh.ValueListInfo info = new net.mlw.vlh.ValueListInfo(filters);ValueList valueList = hibernate4Adapter.getValueList(hql, info);System.err.println(valueList.getList().size());     } catch (Exception e) {e.printStackTrace();}}  
 


有不明白的加群一起讨论:172429747

热点排行