Home>Article>Java> What should I use to connect the return value of mybatis?

What should I use to connect the return value of mybatis?

(*-*)浩
(*-*)浩 Original
2019-05-17 10:56:47 3552browse

What should I use to connect the return value of mybatis? It depends on what data is returned. Common ones are:

What should I use to connect the return value of mybatis?

1. Return the general data type

For example To obtain a field value in the database based on the id attribute.

mapper interface:

// 根据 id 获得数据库中的 username 字段的值 String getEmpNameById(Integer id);

SQL mapping file:

 

2. Return JavaBean type

For example, obtain based on a certain field The information in the database encapsulates the query result information into data of a certain JavaBean type.

mapper interface:

// 根据 id 查询信息,并把信息封装成 Employee 对象 Employee getEmpById(Integer id);

SQL mapping file:

 

3. Return List type

Sometimes we need to query There is more than one piece of data, such as fuzzy query, full table query, etc. At this time, the data returned may be more than one piece of data. For processing of multiple data, it can be stored in the List collection.

mapper interface:

// 假如是全表查询数据,将查询的数据封装成 Employee 类型的集合 List getAllEmps();

SQL mapping file:

 

4. Return Map type

MyBatis also supports encapsulating the queried data into a Map.

1. If the query result is one, we can store the query data into the Map in the form of {table field name, corresponding value}.

mapper interface:

// 根据 id 查询信息,并把结果信息封装成 Map Map getEmpAsMapById(Integer id);

SQL mapping file:

 

The above is the detailed content of What should I use to connect the return value of mybatis?. For more information, please follow other related articles on the PHP Chinese website!

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