-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
MyBatis version
3.2.7
Database vendor and version
MySql 5.6
Test case or example project
In the doc http://www.mybatis.org/mybatis-3/sqlmap-xml.html#insert_update_and_delete
sql
This element can be used to define a reusable fragment of SQL code that can be included in other statements. It can be statically (during load phase) parametrized. Different property values can vary in include instances. For example:
<sql id="userColumns"> ${alias}.id,${alias}.username,${alias}.password </sql>
The SQL fragment can then be included in another statement, for example:
<select id="selectUsers" resultType="map">
select
<include refid="userColumns"><property name="alias" value="t1"/></include>,
<include refid="userColumns"><property name="alias" value="t2"/></include>
from some_table t1
cross join some_table t2
</select>
but my code is
public Map<String,Object> getAllList(String sign) throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("field", "201608_monthdata_"+sign);
map.put("val","weekdata_"+"a349001");
Map<String,Object> m = (Map<String, Object>) dao.findForObject("HarvesterMapper.getAlllist", map);
return m;
}<sql id="sql1">
FROM ems_originaldata.${fieldText}
</sql>
<select id="getAlllist" parameterType="hashmap" resultType="hashmap"> <!-- getAlllist-->
SELECT MAX(receivetime) as lastTime FROM(
SELECT MAX(receivetime) AS receivetime
<include refid="sql1">
<property name="fieldText" value="field"/>
</include>
) aa
</select>the exception is
'''
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 126; columnNumber: 13; 元素类型为 "include" 的内容必须匹配 "EMPTY"。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:256)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:125)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:78)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:462)
... 139 more
'''
mybatis3.2.7 don't super this format?
in xml dtd is
<!ELEMENT property EMPTY>
<!ATTLIST property
name CDATA #REQUIRED
value CDATA #REQUIRED
>
<!-- Dynamic -->
<!ELEMENT include (property+)?>
<!ATTLIST include
refid CDATA #REQUIRED
>