Home  >  Article  >  类库下载  >  Mybatis common summary

Mybatis common summary

高洛峰
高洛峰Original
2016-10-29 13:37:381488browse

1. Parameter injection
1.1 uses the form of #{0}, #{1}, 0 represents the first parameter, 1 represents the second parameter
 public List queryList(String workerId, Integer topNum);

 
1.2Map or encapsulated object, workerId is the key in the map; if it is an object, workerId For attributes in objects, this method is very commonly used
  public Integer queryCountByWorkerId(Map queryParam);
 public Integer queryCountByWorkerId(@param(“workerId”)String workerId); 

2. Return
2.1 mapping

  
  
  
 
 
  select ID,CREATE_DATE,WORKERID from tableName
 
 This way the query statement queries the fields directly It’s just a field in the database, just define the mapped column
2.2 Return the object directly
 

 The field alias returned by the query here must correspond to the attributes in the returned object


3. Execute native sql
3.1sql parameters:    //getter setter omitted

  }

3.2 interface:
  /**
  * @Function description: Create

  * @param vo

  * @return
 */

  public int excuteCreateSql(ParamVo vo);


  /**
  * @Function description: Query
  * @param vo
  * @return
 */
public List
> excuteSelectSql(ParamVo vo);

3.3xml:
 

  ${sql}
 

 ${}Do not compile sql and execute it directly. If you use #{sql}, an error may be reported
  

 ${ sql}  

  I don’t know here whether to use map or hashmap as the return type

4.include: Sometimes the fields to be returned by the two methods are the same or the where clause is the same. In order to avoid duplication of code, just extract it and use include
4.1 The same part of the definition clause
   WHERE F.STATUS = 1 AND F.WORKER_ID = #{workerId}
  ORDER BY C.CREATE_DATE DESC

 


4.2 Quote
  
   SELECT COUNT(1)
  

 
  

   SELECT ID id, WORKER_ID workerId, UPDATE_DATE updateDate,...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Strings in JavaNext article:Strings in Java