分离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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值