Mybatis學習第23節 -- 鑒別器 discriminator
阿新 • • 發佈:2019-03-17
flag doc util val dao test 數據庫表 coins tsql
數據庫表字段
通過vehicle_type判斷是Car還是Suv, 就需要用到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 |
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