Closed GoogleCodeExporter closed 9 years ago
78888888
Original comment by zyqpost...@gmail.com
on 3 Aug 2011 at 5:49
i think it could be
<decorate before="%" after="%">#{title}</decorate> or
<pattern>%#{title}%</pattern>
Original comment by mnesa...@gmail.com
on 1 Sep 2011 at 4:52
Let me throw a few more ideas out there...
<field>%#{title}%</field>
or param which matches the annotation name...
<param>%#{title}%</param>
<param before="%" after="%">#{title}</param>
<param before="%" after="%" name="title"/>
Original comment by brhur...@gmail.com
on 27 Oct 2011 at 12:10
String statement = "afei.person.selectPersons" ;
Person param = new Person();
param.setUsername("%CD%");
param.setPassword("%11%");
List<Person> persons = session.selectList(statement,param) ;
<!-- 模糊查询Person -->
<select id="selectPersons" resultType="person" parameterType="person">
select id,sex,age,username,password from person where true
<if test="username!=null"> AND username LIKE #{username}</if>
<if test="password!=null">AND password LIKE #{password}</if>
</select>
Original comment by 404961...@qq.com
on 23 Dec 2011 at 5:07
[deleted comment]
[deleted comment]
[deleted comment]
[deleted comment]
What about a generic wrapper:
class SQLUtil<T> {
private T m;
private String patternPrefix = "%";
private String patternSuffix = "%";
public SQLUtil(T m) { this.m = m }
public T getM() { return m }
public String pattern(String s) { return patternPrefix + s + patternSuffix }
}
String statement = "afei.person.selectPersons" ;
Person param = new Person();
param.setUsername("CD");
param.setPassword("11");
List<Person> persons = session.selectList(statement,new SQLUtil<Person>(param))
;
<select id="selectPersons" resultType="person" parameterType="sqlutil">
select id,sex,age,username,password from person
<where>
<if test="m.username = null">username LIKE #{_parameter.pattern(m.username)}</if>
</where>
</select>
Is it possible? i have not tested yet.
Original comment by mnesa...@gmail.com
on 26 Mar 2012 at 3:19
According to issue 210, it can be a lot easier:
1. Put a class in default package with static methods like this:
class Util {
public static String pattern(String str, String p, String s) {
return p + str + s;
}
}
2. Then use it with '@':
String statement = "afei.person.selectPersons" ;
Person param = new Person();
param.setUsername("CD");
param.setPassword("11");
List<Person> persons = session.selectList(statement,param) ;
<select id="selectPersons" resultType="person" parameterType="person">
select id,sex,age,username,password from person
<where>
<if test="username != null">username LIKE #{@Util@pattern(username, '%', '%')}</if>
</where>
</select>
I have not tested it.
Original comment by mnesa...@gmail.com
on 26 Mar 2012 at 4:26
Sorry, It does not work.
OGNL is not supported in param positions #{...}
:S
Original comment by mnesa...@gmail.com
on 26 Mar 2012 at 4:47
3.2 will support this:
String statement = "afei.person.selectPersons" ;
Person param = new Person();
param.setUsername("CD");
param.setPassword("11");
List<Person> persons = session.selectList(statement,param) ;
<select id="selectPersons" resultType="person" parameterType="person">
<bind name="pattern" value="'%' + _parameter.username + '%'" />
select id,sex,age,username,password
from person
where username LIKE #{pattern}
</select>
Original comment by mnesa...@gmail.com
on 13 Jun 2012 at 7:41
Use the new bind tag:
<select ...>
<bind name="x" value=" '%' + _parameter.name + '%' " />
SELECT * FROM person WHERE name LIKE #{x}
</select>
Original comment by mnesa...@gmail.com
on 14 Jun 2012 at 4:08
[deleted comment]
[deleted comment]
fix in r5326
Original comment by eduardo.macarron
on 16 Jun 2012 at 3:42
Original issue reported on code.google.com by
q211222...@yahoo.com
on 17 Aug 2010 at 8:47