Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate sort statements automatically by mybatis example

Shulou Source: shulou.com Published: 2022-06-02 06:43:11 10月25日 Update

This article introduces the relevant knowledge of "how to generate sorting statements automatically by mybatis example". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Mybatis example automatically generates code sort statements UserExample ue= new UserExample (); String classLevel = "1"; ue.createCriteria (). AndUserIdEqualTo (classLevel); / / ts is the timestamp ue.setOrderByClause ("ts desc"); List uList = userMapper.selectByExample (ne); example usage of mybatis automatic generation

Example is used to add conditions, which is equivalent to the part after where.

SelectByExample can solve almost all queries.

For example, Example example = new Example (); Example.Criteria criteria = example.createCriteria (); criteria.andStatusEqualTo (1); List list = this.skuMapper.selectByExample (example); list.get (0) is all the data needed for the object query table

SelectByExample (example) returns all the data in the table if it doesn't write the example condition: if it doesn't write example.createCriteria ().

Method description / / 1. Add ascending sort condition, DESC is descending example.setOrderByClause ("field name ASC") / / 2. Remove repetition, boolean type, true to select non-duplicate records example.setDistinct (false) / / 3. Add the condition criteria.andXxxIsNull// 4. 0 where the field xxx is null. Add the condition criteria.andXxxIsNotNull// 5. 0 that field xxx is not null. Add the xxx field equal to the value condition criteria.andXxxEqualTo (value) / / 6. Adding xxx field is not equal to value condition criteria.andXxxNotEqualTo (value) / / 7. Add xxx field greater than value condition criteria.andXxxGreaterThan (value) / / 8. Add xxx field greater than or equal to value condition criteria.andXxxGreaterThanOrEqualTo (value) / / 9. Add xxx field less than value condition criteria.andXxxLessThan (value) / / 10. Add xxx field less than or equal to value condition criteria.andXxxLessThanOrEqualTo (value) / / 11. Add the xxx field value in Listcriteria.andXxxIn (List) / / 12. Do not add xxx field values in Listcriteria.andXxxNotIn (List) / / 13. Add xxx field values between criteria.andXxxBetween (value1,value2) / / 14. Add xxx field value is not between criteria.andXxxNotBetween (value1,value2) "how to automatically generate mybatis example sort statement" content here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Fields conditions automatic generation generation statements sorting between content data more knowledge query utility learning next code examples ascending order dilemma reality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Linux MySQL NVidia