A few options in MyBatis?

I know this question has been asked many times, and I am still having problems when I follow the guide when including several parameters in my selection request. Here is my configuration file:

<select id="selectByDate" parameterType="map" resultMap="campaignStats">
    SELECT * FROM CampaignStats WHERE statsDate >= #{start} AND statsDate <= #{end}
</select>

Here is my Java code:

public List<DpCampaignStats> selectByDate(Date start, Date end){
    SqlSession session = sqlSessionFactory.openSession();
    try {
        Map<String, Date> map = new HashMap<String, Date>();
        map.put("start", start);
        map.put("end", end);
        List<DpCampaignStats> list = session.selectList("DpCampaignStats.selectByDate", map);
        return list;
    } finally {
        session.close();
    }
}

But I get an error: java.lang.ExceptionInInitializerError, which means that I have some errors in the configuration file, and I can not find the reason.

+5
source share
2 answers

I found the answer myself: '<' and '>' have certain values ​​in xml files, so '> =' should be '& gt = =, while' <= 'should be' & lt; = '.

+3
source

Just wrap the SQL statement in CDATA:

<![CDATA[
   SELECT * FROM CampaignStats WHERE statsDate >= #{start} AND statsDate <= #{end}
]]>
+11
source

All Articles