Mybatisの特殊記号(より大きい、より小さい、等しくない)および一般的に使用される関数の要約
Mybatis Special Symbols Greater Than
目次
シーンを使う
大なり記号(>、> =)、小なり記号(>、> =)を使用することが多いため、<, <=), not equal (, !=) symbols in the daily code Mybatis dynamic stitching statements. Since this symbol contains angle brackets, the *.xml file format used by Mybatis. then
CDATAセクションをエスケープまたは使用するには、山括弧を使用する必要があります。
2、実装
2.1、特別なシンボルモードをエスケープする
注:厳密に言えば、文字のみ '<' and '&' in XML are illegal. Ellipses, quotes, and greater than are legal, but it is a good practice to replace them with entity references.
シンボル | 元のシンボル | 置換記号 |
---|---|---|
未満 | < | &lt |
以下 | <= | &lt = |
以上 | >> | &gt |
以上以上 | > = | &gt = |
等しくない | &lt&gt | |
対 | & | &amp |
アポストロフィ | ' | &apos |
二重引用符 | ' | &quot |
Mapper file writing: select * form tablenme t where t.code <> 1
2.2、CDATAセクションの使用
すべてのXMLドキュメントのテキストは、パーサーによって解析されます。 CDATAセクションのテキストのみがパーサーによって無視されます。
Greater than or equal to = ]]> Less than or equal to Mapper file writing: select t.* form tablenme t where t.code 1
3、文字列と等しいと判断された場合のMybatis
渡された型の値がメモの場合、ifステートメント内のSQLは実行されません。
and status = 0
Mybatisは、OGNL式を使用して解析されます。 OGNL式では、javaは強く型付けされており、charとStringは等しくない可能性があるため、「note」は文字に解析されます。したがって、ifタグのSQLは解析されません。
この問題を解決する必要があります。コードを次のように変更するだけです。
//Note that it is double quotes, not single quotes! ! ! and status = 0
4、mysqlバイナリを文字列に
SELECT cast(fieldName as CHAR) FROM tablename