--- /dev/null
+package de.example.mybatis.repository.mapper;
+
+import java.util.Set;
+
+import de.example.mybatis.mapper.filter.MyBatisScanFilter;
+import de.example.mybatis.model.Ad;
+
+
+public interface AdCustomMapper extends MyBatisScanFilter {
+
+ Set<Ad> selectAds();
+}
import org.apache.log4j.Logger;
+import de.example.mybatis.spring.service.ExampleCustomService;
import de.example.mybatis.spring.service.ExampleService;
public class TestMain {
exampleService.insertNewAd();
exampleService.getAdsByCriteria();
+
+
+ final ExampleCustomService exampleCustomService = (ExampleCustomService) SpringContextLocator
+ .getInstance().getBean("exampleCustomService");
+
+ exampleCustomService.getAds();
}
}
--- /dev/null
+package de.example.mybatis.spring.service;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import de.example.mybatis.model.Ad;
+import de.example.mybatis.repository.mapper.AdCustomMapper;
+
+
+public class ExampleCustomService {
+ private static final Logger logger = Logger.getLogger(ExampleService.class);
+
+ private AdCustomMapper adCustomMapper;
+
+ public void setAdCustomMapper(final AdCustomMapper adCustomMapper) {
+ this.adCustomMapper = adCustomMapper;
+ }
+
+ public void getAds() {
+ logger.info("ExampleCustomService: getAds");
+
+ final Set<Ad> ads = this.adCustomMapper.selectAds();
+
+ for (final Ad ad : ads) {
+ logger.info("Ad id: " + ad.getId());
+ if (ad.getAdGps() != null) {
+ try {
+ logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
+ } catch (final UnsupportedEncodingException e) {
+ logger.error("Encoding error", e);
+ }
+ }
+ logger.info("Ad mobileImage: " + ad.getAdMobileImage());
+ logger.info("Ad companyCategId: " + ad.getCompanyCategId());
+ logger.info("Ad companyId: " + ad.getCompanyId());
+ logger.info("Ad createdAt: " + ad.getCreatedAt());
+ logger.info("Ad updatedAt: " + ad.getUpdatedAt());
+ logger.info("\n");
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="de.example.mybatis.repository.mapper.AdCustomMapper" >
+ <select id="selectAds" resultType="de.example.mybatis.model.Ad" flushCache="false" useCache="true" timeout="10000" statementType="PREPARED">
+ select * FROM ad
+ </select>
+</mapper>
\ No newline at end of file
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin">
</plugin>
+ <!-- Not very useful because you can not rely on its results (equals/hashcode depend on bussines rules)
+ <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin">
+ </plugin>
+
+ <plugin type="org.mybatis.generator.plugins.SerializablePlugin">
+ <property name="suppressJavaInterface" value="true"/>
+ </plugin>
+ -->
+
+
<commentGenerator>
<property name="suppressAllComments" value="false" />
<property name="suppressDate" value="false" />
</jdbcConnection>
<javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
+ <property name="forceBigDecimals" value="true" />
</javaTypeResolver>
<javaModelGenerator targetPackage="de.example.mybatis.model" targetProject="MAVEN">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
+ <!--
+ There is no need of declaring every table in data base.
+
<table schema="mybatis_example" tableName="ad" domainObjectName="Ad">
<property name="useActualColumnNames" value="false" />
<property name="ignoreQualifiersAtRuntime" value="true" />
- <!--
<mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation
- -->
<property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
<generatedKey column="id" sqlStatement="MySql" identity="true" type="post" />
</table>
<table schema="mybatis_example" tableName="ad_description" domainObjectName="AdDescription">
<property name="useActualColumnNames" value="false" />
<property name="ignoreQualifiersAtRuntime" value="true" />
- <!--
<mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation
- -->
<property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
<generatedKey column="id" sqlStatement="MySql" identity="true" type="post" />
</table>
+ -->
+
+ <table tableName="%"
+ enableSelectByExample="true"
+ enableDeleteByExample="true"
+ enableCountByExample="true"
+ enableUpdateByExample="true"
+ selectByExampleQueryId="true">
+ <property name="useActualColumnNames" value="false" />
+ <property name="ignoreQualifiersAtRuntime" value="true" />
+ <property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
+ <!--
+ <mybatis:scan/> supports filtering the mappers created by either specifying a marker interface or an annotation
+ -->
+ <property name="rootInterface" value="de.example.mybatis.mapper.filter.MyBatisScanFilter" />
+ <generatedKey column="id" sqlStatement="MySql" identity="true" type="post" />
+ </table>
</context>
</generatorConfiguration>
<bean id="exampleService" class="de.example.mybatis.spring.service.ExampleService">
<property name="adMapper" ref="adMapper" />
</bean>
+
+ <bean id="exampleCustomService" class="de.example.mybatis.spring.service.ExampleCustomService">
+ <property name="adCustomMapper" ref="adCustomMapper" />
+ </bean>
</beans>