在application.yaml文件中添加配置:
mybatis-plus:configuration:default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
测试
@Test
void testService() {List<User> list = userService.list();list.forEach(System.out::println);
}
最终,查询出的
User
类的status
字段会是枚举类型:同时,为了使页面查询结果也是枚举格式,我们需要修改UserVO中的status属性:
并且,在UserStatus枚举中通过
@JsonValue
注解标记JSON序列化时展示的字段:最后,在页面查询,结果如下: