简体   繁体   中英

Different result mappings for the same query but with variable column - MyBatis 3

I need to get different java Pojo result mapping from same query with different column in sql "Where" condition. Es.

@Select("Select field1,fiel2,...,fieldn From table where #{column}=1")
List<Pojo> getGenericDetails(@Param(column));

Mybatis "discriminator" doesn't make the job. Can anyone know how to do that?

Thanks in advance

If want to get different java Pojo result mapping from the same query with different column in SQL "Where" condition, I will try the following:

@Select("Select field1,fiel2,...,fieldn From table where #{column}=1")
List<Map<String,Object>> getGenericDetails(@Param(column));

as a result, the key in the map is the field1,fiel2,...,fieldn the value will be the result of field1,fiel2,...,fieldn.

Hope the above helps.

The Mapping what you have written works But it works on same POJO .

If you need different POJOs based on the column in where clause then you Have to write different queries for each of condition in where clause .

Which is as good as specifying column name in query .

So i suggest you to write different queryies and created Different POJOs and make the method name relevant to context where you will use those queryies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM