1.定义配置类 tk.mybatis.spring.mapper.MapperScannerConfigurer
//配置類 @Configuration public class IdConfig { @Bean public MapperScannerConfigurer mapperScannerConfigurer(){ MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); mapperScannerConfigurer.setBasePackage("com.foxconn.svcapollo.mapper"); Properties propertiesMapper = new Properties(); //通用mapper位置,不要和其他mapper、dao放在同一个目录 propertiesMapper.setProperty("mappers", "com.foxconn.svcapollo.config.MyMapper"); propertiesMapper.setProperty("notEmpty", "false"); //主键UUID回写方法执行顺序,默认AFTER,可选值为(BEFORE|AFTER) propertiesMapper.setProperty("ORDER","BEFORE"); mapperScannerConfigurer.setProperties(propertiesMapper); return mapperScannerConfigurer; } }2.定义通用mapper配置类,继承Mapper,MySqlMapper
//通用mapper配置類 public interface MyMapper<T> extends Mapper<T>,MySqlMapper<T> { }3.dao层继承MyMapper
@Mapper public interface ConsignmentDao2 extends MyMapper<Apo_Ack_Delivery_Line>{}4.实体类定义
@Table(name="APO_ACK_DELIVERY_LINE", schema="RMADB3") public class Apo_Ack_Delivery_Line { @Id @GeneratedValue(strategy = GenerationType.IDENTITY,generator = "select RMADB3.APO_ACK_DELIVERY_LINE_ID.nextval from dual") private Integer id; private String deliveryNumber; }