The bahviour observed when mapping a string collection does not feel very obvious to me. I only figured out how thanks to this thread:
For the following SQL statement:
select id, str from testTable
where testTable contains:
1 | A |
1 | B |
And where we expect a single result row with the content:
{"id": 1, "str": ["A", "B"]}
this must be mapped as follows:
<resultMap id="stringsResultOk" type="java.util.Map">
<id column="id" property="id" />
<collection property="strings" ofType="java.lang.String" javaType="list">
<result column="str" />
</collection>
</resultMap>
I'd usually expect that the <result>
tag in the collection would refer to a property of an item in the collection which of course would not make any sense for items of type string. However it works perfectly fine.
On the otherhand this mapping:
<resultMap id="stringsWrongColumnMapping" type="java.util.Map">
<id column="id" property="id" />
<collection property="strings" column="str" ofType="java.lang.String" javaType="list" />
</resultMap>
would seem to be the natural choice for me, however the "column" attribute seems to have no effect. (It is only used for Nested Select for Collection
?). Instead this mapping will just be filled with a value from the id
column which does seem rather random.
The following mapping won't work either:
<resultMap id="stringsMissingJavaType" type="java.util.Map">
<id column="id" property="id" />
<collection property="strings" ofType="java.lang.String">
<result column="str" />
</collection>
</resultMap>
This does not work because the collection does not specify a javaType for the collection. Instead the tag will generate just a single plain string which is quite a surprise because it is most definitly not a collection as the tag <collection>
would suggest.
I suggest to either change the behaviour of the later two mapping types or throw some helpful exceptions that point one to the right direction about what is wrong. And maybe extend the documentation about how the mapping for collection of simple types works (if I haven't accidentially missed it).
See some tests that illustrate my findings with some real code here:
https://github.com/yankee42/mybatis-string-collection
来源:https://github.com/mybatis/mybatis-3/issues/364
相关推荐
Working with XML in Word <br> Introduction to Word's XML Features <br> An End-to-End Scenario: Creating a Schema and Mapping It into a Word Document <br> Exporting the Mapped XML in the Document to ...
Working with XML in Word <br> Introduction to Word's XML Features <br> An End-to-End Scenario: Creating a Schema and Mapping It into a Word Document <br> Exporting the Mapped XML in the Document to ...
<br><br>The topics covered include: <br><br>Dividing an enterprise application into layers <br>The major approaches to organizing business logic <br>An in-depth treatment of mapping between objects ...
This could be used for what i used it for in the past for a news program<END><br>28 , url.zip<br>Worldwide list of URL extensions by country<END><br>29 , EmailChk.zip<br>This Application checks for ...
Building Data-Driven Solutions 第一部分<br>Table of Contents <br> Applied ADO.NET—Building Data-Driven Solutions <br> Introduction <br> Chapter 1 - ADO.NET Basics <br> Chapter 2 - Data Components in ...
<mime-mapping> <extension>htm</extension> <mime-type>text/html;charset=gb2312</mime-type> </mime-mapping> <mime-mapping> <extension>html</extension> <mime-type>text/html;charset=gb2312</mime-...
MMU - maps CPU virtual addresses into physical addresses, for valid mappings<br> TRAP - an interruption in the normal sequencing of a CPU due to an invalid<br> memory mapping, a trap, exception, or an...
The Scheme<br>Programming Language<br><br>... Multitasking with Engines <br><br>Bibliography<br><br>Answers to Selected Exercises<br><br>Formal Syntax of Scheme<br><br>Summary of Forms<br><br>Index<br>
<servlet> <servlet-name>HelloWorldname</servlet-name> <!-- 此说明该<servlet/> 已经得到了注册名HelloWorldname, 既此servlet已经得到了注册名HelloWorldname, 它与<servlet-mapping/>必须注册同样的注册...
例如:<filter-mapping><filter-name>CocoSystemAuthFilter</filter-name><url-pattern>firstServlet(servlet 名称)</url-pattern>或者 URL 模式<url-pattern>/*.do(URL 字符串)</url-pattern></filter-mapping> ...
column="EVENT_ID"><br> <generator class="native"/><br> </id><br> <property name="date" type="timestamp" column="EVENT_DATE"/><br> <property name="title"/><br> </class><br><br></hibernate-mapping><br>...
guidance for designers and reviewers<br><br>Examples from a wide range of application domains<br><br>Rely on this book as the world's #1 reference to reusable use-case solutionsand as a catalyst for ...
hibernate-mapping<br>5.1.3. class<br>5.1.4. id<br>5.1.4.1. generator<br>5.1.4.2. 高/低位算法(Hi/Lo Algorithm)<br>5.1.4.3. UUID算法(UUID Algorithm )<br>5.1.4.4. 标识字段和序列(Identity columns ...
hibernate-mapping<br>5.1.3. class<br>5.1.4. id<br>5.1.4.1. generator<br>5.1.4.2. 高/低位算法(Hi/Lo Algorithm)<br>5.1.4.3. UUID算法(UUID Algorithm )<br>5.1.4.4. 标识字段和序列(Identity columns ...
It also aims to collect and disseminate information in various disciplines including: <br>Computer Graphics <br>Computer Vision <br>Computer Aided Geometric Design <br>Geometric Algorithms <br>...
name>encoding</param-name><br> <param-value>utf-8</param-value><br> </init-param><br> <init-param><br> <param-name>forceEncoding</param-name><br> <param-value>true</param-value><br> </init-...
<extension>.aif</extension> <mime-type>audio/x-aiff</mime-type> </mime-mapping> <mime-mapping> <extension>.aiff</extension> <mime-type>audio/x-aiff</mime-type> </mime-mapping> <mime-mapping> ...
Java正则表达式 <br>批量上传--采集 (多个文件夹)<br>The Agile Way<br>hibernate mapping文件中的标记详解:关系标记<br>ANT 安装使用及build.xml文档模板<br>inverse和cascade在关联更新中的作用<br>hibernate ...
<filter-mapping> <filter-name>shiroFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> maven 的pom.xml 配置 <!-- shiro简单配置 --> <dependency> <groupId>org.apache....
<trim-strings>true</trim-strings> </configuration> <!-- <mapping date-format="yyyy-MM-dd"> <class-a>com.vine.dozer.model.Model1</class-a> <class-b>com.vine.dozer.model.Info1</class-b> <field> ...