<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
- <version>3.2.2</version>
+ <version>3.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
--- /dev/null
+package de.example.mybatis.repository.mapper;
+
+import java.util.List;
+
+import de.example.mybatis.model.Ad;
+
+
+public interface ChildMapper extends ParentMapper {
+
+ List<Ad> selectAdsChild();
+}
--- /dev/null
+package de.example.mybatis.repository.mapper;
+
+import java.util.List;
+
+import de.example.mybatis.mapper.filter.MyBatisScanFilter;
+import de.example.mybatis.model.Ad;
+
+
+public interface ParentMapper extends MyBatisScanFilter {
+
+ List<Ad> selectAdsParent();
+}
import de.example.mybatis.spring.service.BatchAndSimpleSameTrx;
import de.example.mybatis.spring.service.ExampleBatchService;
import de.example.mybatis.spring.service.ExampleCustomService;
+import de.example.mybatis.spring.service.ExampleInheritanceService;
import de.example.mybatis.spring.service.ExampleService;
public class TestMain {
// exampleBatchService.insertBatchNewAd();
- final BatchAndSimpleSameTrx batchAndSimpleSameTrx = (BatchAndSimpleSameTrx) SpringContextLocator
- .getInstance().getBean("batchAndSimpleSameTrx");
+// final BatchAndSimpleSameTrx batchAndSimpleSameTrx = (BatchAndSimpleSameTrx) SpringContextLocator
+// .getInstance().getBean("batchAndSimpleSameTrx");
+//
+// try {
+// batchAndSimpleSameTrx.insertNewAd();
+// } catch (CannotGetJdbcConnectionException e) {
+// logger.error("Error exception: ", e);
+// } catch (SQLException e) {
+// logger.error("Error exception: ", e);
+// }
- try {
- batchAndSimpleSameTrx.insertNewAd();
- } catch (CannotGetJdbcConnectionException e) {
- logger.error("Error exception: ", e);
- } catch (SQLException e) {
- logger.error("Error exception: ", e);
- }
+ final ExampleInheritanceService exampleBatchService = (ExampleInheritanceService) SpringContextLocator
+ .getInstance().getBean("exampleInheritanceService");
+
+ exampleBatchService.selectAdsParent();
+ exampleBatchService.selectAdsChild();
}
}
--- /dev/null
+package de.example.mybatis.spring.service;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.example.mybatis.model.Ad;
+import de.example.mybatis.repository.mapper.ChildMapper;
+import de.example.mybatis.repository.mapper.ParentMapper;
+
+
+public class ExampleInheritanceService {
+ private static final Logger logger = Logger.getLogger(ExampleService.class);
+
+ private ChildMapper childMapper;
+ private ParentMapper parentMapper;
+
+ public void setChildMapper(final ChildMapper childMapper) {
+ this.childMapper = childMapper;
+ }
+
+ public void setParentMapper(final ParentMapper parentMapper) {
+ this.parentMapper = parentMapper;
+ }
+
+ public void selectAdsChild() {
+ logger.info("ExampleCustomService: getAds");
+
+ final List<Ad> ads = this.childMapper.selectAdsChild();
+
+ 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");
+ }
+ }
+
+ public void selectAdsParent() {
+ logger.info("ExampleCustomService: updateAds");
+
+ final List<Ad> ads = this.childMapper.selectAdsParent();
+
+ 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.ChildMapper">
+
+ <select id="selectAdsChild" resultType="de.example.mybatis.model.Ad">
+ select * FROM ad
+ </select>
+
+</mapper>
\ No newline at end of file
--- /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.ParentMapper">
+
+ <select id="selectAdsParent" resultType="de.example.mybatis.model.Ad">
+ select * FROM ad
+ </select>
+
+</mapper>
\ No newline at end of file
<property name="adMapper" ref="adMapper" />
<property name="dataSource" ref="dataSource" />
</bean>
+
+
+ <!--
+ MyBatis mappers inheritance
+ -->
+
+ <bean id="exampleInheritanceService" class="de.example.mybatis.spring.service.ExampleInheritanceService">
+ <property name="childMapper" ref="childMapper" />
+ <property name="parentMapper" ref="parentMapper" />
+ </bean>
</beans>