简体   繁体   中英

Element type “foreach” must be declared - mybatis

Is using foreach attribute in mybatis/ibatis for oracle sql updates a best practice? Below is my query in the sql map.

<update id="updateFG"  parameterClass="java.util.Map">
    
        <foreach collection="entries.entrySet()" item="item" index="index" >
            UPDATE <<tablename>>
            SET description = #{item.value},
                last_mod_date= SYSDATE
            WHERE name = #{item.key}
        </foreach>
        
    </update>

When I try to run this piece of code it is throwing me an error:

Error parsing XML. Cause: org.xml.sax.SAXParseException; lineNumber: 49; columnNumber: 72; Element type "foreach" must be declared.

Okay so when I changed my DCOTYPE from sqlmap to mapper - it worked fine.. I think foreach cannot be used for sqlMap..

EDIT: realized the foreach is not efficient for multiple rows so used batch instead

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