Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from chrobin/master
Browse files Browse the repository at this point in the history
修正suffix的处理
  • Loading branch information
hhyo authored Feb 21, 2019
2 parents b6da5f9 + 86cc616 commit e88a37c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mybatis_mapper2sql/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ def convert_choose_when_otherwise(mybatis_mapper, child):
def convert_trim_where_set(mybatis_mapper, child):
if child.tag == 'trim':
prefix = child.attrib.get('prefix')
suffix = child.attrib.get('suffix')
prefix_overrides = child.attrib.get('prefixOverrides')
suffix_overrides = child.attrib.get('suffix_overrides')
suffix_overrides = child.attrib.get('suffixOverrides')
elif child.tag == 'set':
prefix = 'SET'
suffix = None
prefix_overrides = None
suffix_overrides = ','
elif child.tag == 'where':
prefix = 'WHERE'
suffix = None
prefix_overrides = 'and|or'
suffix_overrides = None
else:
Expand All @@ -151,6 +154,8 @@ def convert_trim_where_set(mybatis_mapper, child):
# Add Prefix if String is not empty
if re.search('\S', convert_string):
convert_string = prefix + ' ' + convert_string
if suffix:
convert_string = convert_string + ' ' + suffix
# Add trim/where/set tail
convert_string += convert_parameters(child, tail=True)
return convert_string
Expand Down
25 changes: 25 additions & 0 deletions tests/test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,29 @@
WHERE
name like #{likeName}
</select>
<insert id="testInsertSelective">
insert into fruits
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
name,
</if>
<if test="category != null">
category,
</if>
<if test="price != null">
price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name},
</if>
<if test="category != null">
#{category},
</if>
<if test="price != null">
#{price},
</if>
</trim>
</insert>
</mapper>

0 comments on commit e88a37c

Please sign in to comment.