Crud construction of general Mybatis

Universal Design for CRUD

1. Query entity class information through primary key

The principle of selectByPrimaryKey(T.class, Object primaryKey) 
: Obtain the primary key, field, table name and other information in the class through reflection, query the data through Mybatis, and package the queried data into an instance of the T object

2. Insert the test data
insertSelective(T t)
Principle: Query the table name, field name, and field value according to t, package it into a map, and save it
3. Delete data according to the primary key
deleteByPrimaryKey(Class<T> clazz, Object primaryValue) 
queries the table name and primary key name of the class through reflection. Pack the table name, primary key name, and primary key value into a map and pass it to Mybatis as a parameter
4. Update the object according to the primary key
<T> int updateByPrimaryKey(T t) throws Exception; 
query T's table name, primary key value, primary key name, field name, field value according to reflection, and then update the class value according to the primary key

5. Batch insert data
insertBatch(List<T> list) 
traverses the list to obtain the value of each element and the corresponding T, and generates the sql field object of the object

6. Delete according to conditions
deleteByCondition(Class<T> clazz, String conditionExp, Map<String, Object> conditionParam) 
7. Paging query
<T> List<T> selectAdvanced(Class<T> clazz, GeneralQueryParam queryParam) throws Exception
queryParam:queryClazz,queryColumn,conditionExp,conditionParam,pageSize,pageNo,orderExp


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325288064&siteId=291194637