把integer类型映射成string类型,利用like对字符串的hql模糊查询。
比如对vo中定义的integer主键进行模糊查询:
<id
name="estId"
column="EST_ID"
type="java.lang.Integer"
>
<generator class="native"/>
</id>
可以定义一个多余的字段,改为string类型:
<property
name="strId"
type="java.lang.String"
[color=red]update="false"
insert="false"[/color]
access="property"
column="EST_ID"
length="10"
not-null="false"
unique="false"
/>
注意update、insert配置为false.
查询hql 写法:
sql.append( " and a.strId like:estId" );
countSql.append( " and a.strId like:estId" );
pars.put( "estId", '%'+ model.getEstName()+'%');
附注:java中判断输入文字是数字的方法:
Pattern pattern = Pattern.compile("[0-9]*");
if(pattern.matcher(model.getEstName()).matches())
{
满足条件……
}
比如对vo中定义的integer主键进行模糊查询:
<id
name="estId"
column="EST_ID"
type="java.lang.Integer"
>
<generator class="native"/>
</id>
可以定义一个多余的字段,改为string类型:
<property
name="strId"
type="java.lang.String"
[color=red]update="false"
insert="false"[/color]
access="property"
column="EST_ID"
length="10"
not-null="false"
unique="false"
/>
注意update、insert配置为false.
查询hql 写法:
sql.append( " and a.strId like:estId" );
countSql.append( " and a.strId like:estId" );
pars.put( "estId", '%'+ model.getEstName()+'%');
附注:java中判断输入文字是数字的方法:
Pattern pattern = Pattern.compile("[0-9]*");
if(pattern.matcher(model.getEstName()).matches())
{
满足条件……
}