欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

分开valuelist的sql拼装

更新时间: 2014-01-05 02:06:41 责任编辑: Author_N1

 

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

<bean id="hibernate4Adapter" class="net.mlw.vlh.adapter.hibernate4.Hibernate4Adapter">
    //jap的
<property name="sessionFactory" ref="entityManagerFactory" />
    //hibernate的
<property name="sessionFactoryBean" ref="sessionFactoryBean" />
</bean>

<bean id="columnMapRowMapper" class="org.springframework.jdbc.core.ColumnMapRowMapper" />
<bean id="sqlPagingSupport" class="net.mlw.vlh.adapter.jdbc.util.SqlPagingSupport" />

<bean id="jdbcAdapter" class="net.mlw.vlh.adapter.jdbc.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}
 
 
  
  @Autowired
	public Hibernate4Adapter hibernate4Adapter;
	
	@Autowired
	private JdbcAdapter jdbcAdapter;
	
	@Test
	public 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();
		}
	}
   
   	@Test
	public 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
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:06:41
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/5729/
本文WWW.DOC100.NET DOC100.NET版权所有。