MyBatis Dynamic SQL statements (OGNL syntax)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.