Mybatis学习第23节 -- 鉴别器 discriminator
Posted 积水成渊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mybatis学习第23节 -- 鉴别器 discriminator相关的知识,希望对你有一定的参考价值。
discriminator或者叫做分类器
Vehicle类
package io.github.coinsjack.pojo;
}
|
Car继承自Vehicle
package io.github.coinsjack.pojo;
|
Suv继承自Vehicle
package io.github.coinsjack.pojo;
|
数据库表字段
id int(11) NO PRI auto_increment vin varchar(50) YES year year(4) YES make varchar(50) YES model varchar(20) YES color varchar(20) YES vehicle_type int(11) YES door_count int(11) YES all_wheel_drive tinyint(1) YES |
通过vehicle_type判断是Car还是Suv, 就需要用到discriminator
VehicleMapper映射文件
<?xml version="1.0" encoding="UTF-8" ?>
|
测试
@Test
|
测试结果
2018-12-29 17:38:29,567 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - ==> Preparing: select * from tb_vehicle WHERE `id` = ?; 2018-12-29 17:38:29,677 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - ==> Parameters: 5(Integer) 2018-12-29 17:38:29,750 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - <== Total: 1 查询结果: Car{doorCount=4, id=5, vin=‘2627159999‘, year=Mon Jan 01 08:00:00 CST 2018, make=‘IDEA‘, model=‘DA-20‘, color=‘Black‘} 2018-12-29 17:38:29,762 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - ==> Preparing: select * from tb_vehicle WHERE `id` = ?; 2018-12-29 17:38:29,763 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - ==> Parameters: 6(Integer) 2018-12-29 17:38:29,804 [main] DEBUG [io.github.coinsjack.dao.VehicleMapper.getVehicleById] - <== Total: 1 查询结果: Suv{allWheelDriveFlag=false, id=6, vin=‘2627159998‘, year=Mon Jan 01 08:00:00 CST 2018, make=‘IDEA‘, model=‘AA-19‘, color=‘Pink‘} |
以上是关于Mybatis学习第23节 -- 鉴别器 discriminator的主要内容,如果未能解决你的问题,请参考以下文章