mybatis use annotations to write dynamic sql Notes - turn

First, write format

Form 1, using @Select ({ "<script>" sql statement "</ script>"}) package sql statement. Note that {}, "<script>" and "</ script>", can not do without, for example:

@Select({"<script>",

"Sql statement"

"</script>"})

2, requires the use of a comma between the connecting line to line sql statement:

 

 

Second, the condition determination

1, multi-condition determination, using the "<when ​​test = 'state == 1'>", "sql statement", "</ when>" or

"<if test = 'state == 1'>", "sql statement", "</ if>" form. Wherein the state == 1 for the determination of the conditions must be the same format.

2, the determination condition is a string, the string Test double quotes inside to escape, for example: test = 'dbtype = \ " mysql \"!'

Third, greater than, less than replacement symbol

Sql statement is prepared by dynamic annotation, the portion where use is greater than, less than or equal sign, can not directly use the ">" and "<", needs to be replaced, MyBatis to run properly. Alternatively the control as follows:

Original Address: https://mbd.baidu.com/newspage/data/landingshare?pageType=1&isBdboxFrom=1&context=%7B%22nid%22%3A%22news_9416527835807077854%22%2C%22sourceFrom%22%3A%22bjh%22% 7D

Guess you like

Origin www.cnblogs.com/zbq6/p/12501435.html