MyBatis and Spring Settings callsettersonnulls

Source: Internet
Author: User
The project integrates MyBatis with spring and uses Mybatis3.2.7, as well as spring4.0.5,mybatis-spring-1.2.2;
Because team members want to be lazy, when querying data from DB, they need to map the fields to map instead of being encapsulated as beans.

By default, MyBatis the resolution of the map, and if the value (value) is null, then key is not added to the map.
So when the map traversal, key will not be traversed, because the front-end tool needs, must have this key, online search found that need to set callsettersonnulls this attribute.
Then set it up. In the definition of sqlsessionfactory, specify the Configlocation property and point to another file, as shown below

List of documents: Mybatis-env-setting.xml
[HTML]  View plain  copy   <?xml version= "1.0"  encoding= "UTF-8"?>   <! doctype configuration        PUBLIC  "-//mybatis.org//dtd  config 3.0//en "        " Http://mybatis.org/dtd/mybatis-3-config.dtd " >       <!--        if the intranet machine complains, please use the following stupid method    -- >   <!--    <! doctype configuration           PUBLIC  "-// Www.mybatis.org//DTD Config 3.0//EN "           " e:/ Bao/tomcat/apache-tomcat-6.0.14/webapps/pmsys/web-inf/classes/mybatis/mybatis-3-config.dtd ">    -->      <configuration>       <settings>          <!--  Only set required, others using default values &NBSP;-->         <!--  Open cache, the default is open, 2-layer switch, need in mapper file also specified   cache  tags will actually use caching  -->         <setting name= " Cacheenabled " value=" true "/>         <!--  also called on null  setter, suitable for returning map,3.2 version above available  -->           < Setting name= "Callsettersonnulls"  value= "true"/>       </settings >   </configuration>  
Then use, all normal, OK.
After a few days, the implementation of the project was a bug, because it is the intranet server, can not access the mybatis.org, and then start an error.
"MyBatis this slag, the DTD is fetched and validated at startup, and it is not known where to configure it to not validate."
Online search for half a day, there is no good solution, see a way to say that the DTD download to the local, and then directly specify the path, as noted above the part of the same.

The problem is solved, but very soil, and each machine does not necessarily have the same directory, this method of slag drop will certainly be criticized.
So Baidu Google search for a long time, did not find a way, there is no one to mention this stubble.

So think of their own turn over the source to see:
[Java]  View Plain  copy   public class sqlsessionfactorybean         implements FactoryBean<SqlSessionFactory>, InitializingBean,        ApplicationListener<ApplicationEvent> {         Private static final log logger = logfactory.getlog (SqlSessionFactoryBean.class) ;     //  Here you can configure Configlocation resources      private Resource  configlocation;        private Resource[] mapperLocations;  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.