Expected one result (or null) to be returned by () and set the database results java example selectOne

mybatis will set an example to initialize java based on the results of the query.

If a complex type, we will generally do a good job of mapping in mapper.

1. Therefore, if the query result is a plurality, then the corresponding java type must be of the type set. (Result is the generic type or collection of elements, dao interface must be set)

    Such as: xml: <select id = 'xx' resultType = 'java.lang.String'> Interface: String [] xx ();

2. However, there is a result, although a plurality of sets, but needs to be an example.

  Such as: query classes and students SELECT * FROM clazz LEFT JOIN student on. . . .

  We java example is the corresponding clazz i.e. {clazzName, student []}.

  So this statement, as long as not only a student so sure there will be more results. But we need to create an instance mybatis for us.

  This is resultMap, resultType difference. resultMap we do mappings, there are collection properties, so mybatis creates an instance for us.

  If you use resultType, mybatis would say: Expected one result (or null) to be returned by selectOne (). Check out several, you have a, to which ah?

So, this problem Expected one result (or null) to be returned by selectOne (). The first is to produce more than one result, we have more, but receiving the wrong type. The second is to produce more, but we need one, (because in fact the result of multiple java is an example) then it is not doing the mapping, or use resultType, rather than resultMap.

 

Guess you like

Origin www.cnblogs.com/ming-question/p/11760803.html