The following is a simple case of mybatis Dynamic SQL statements (that is, the ognl syntax )
1. Create a table
Create TableTest (IDint Primary KeyAuto_increment,namevarchar( -), Jobvarchar( -), Deptvarchar( -), Salint) CharSet=UTF8;Insert intoTestValues(NULL,'Luban','Java','Armor',1456),(NULL,'Descendants','Java','Armor',2440),(NULL,'Liu Chan','C','Armor',3540),(NULL,'Liu Bei','python','Armor',4505),(NULL,'Guan Yu','python','b',1470),(NULL,'Zhang Fei','C','b',2345),(NULL,'Dee','Java','b',3640),(NULL,'King of Lan Ling','C','C',4000),(NULL,'Mulan','C','C', +),(NULL,'Zhuge Liang','Java','C',2047),(NULL,'Shing','python','Ding', the),(NULL,'Little Joe .','C','Ding',4000),(NULL,'female snail','Java','Ding', +),(NULL,'Natalie','Java','Ding',6705),(NULL,'Gongsunze','Java','Ding',NULL),(NULL,'Thyme Compliance','C','Armor',NULL),(NULL,'Xiao Liu','python','Ding',842),(NULL,'Cai Wenji','python',NULL, -);
Create test Table
Use of 2.<if> tags
<SelectID= "Selecttest"Resulttype= "Bean. Testbean "ParameterType= "Bean. Testbean ">SELECT * FROM Test where<ifTest= "job!=null"><!--------------------Here the job nature calls the get () method of the ParameterType parameter -name=#{}<!--------------------So the parameter cannot be a base type (because the base type and wrapper class do not have a get () method) - </if>or name= ' descendants '<!--------------------if job equals null (that is, parameter. Getjob () equals null), then the statement SQL statement becomes as follows - <!--------------------Select * from where or name= ' descendants ' error! , the where tag is used to prevent this from happening - </Select>
---restore content ends---
MyBatis Dynamic SQL statements (OGNL syntax)