mybatis plus Integer映射为枚举和json映射为对象
3月 15, 2023 |
Nix.Huang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
@Configuration public class Config { //将Integer 映射未枚举处理器 @MappedTypes({MState.class}) @MappedJdbcTypes(value ={JdbcType.TINYINT, JdbcType.INTEGER}) public static class MStateTypeHandler extends EnumOrdinalTypeHandler<MState> { public MStateTypeHandler() { super(MState.class); } } //JSON处理器 @MappedTypes({EventHandlingContext.class}) @MappedJdbcTypes(value ={JdbcType.VARCHAR, JdbcType.UNDEFINED}) public static class EventHandlingContextHandler extends FastjsonTypeHandler { public EventHandlingContextHandler() { super((Class)EventHandlingContext.class); } } //将处理器注册未bean @Bean public MStateTypeHandler getTypeHandlerForMState() { return new MStateTypeHandler(); } @Bean public FastjsonTypeHandler getJsonTypeHandler() { return new EventHandlingContextHandler(); } } |