## 在springboot中使用MyBatis-Plus处理JSON字符串时出现的异常 数据库的user表中有一个info字段,是JSON类型;目前User实体类中却是String类型;为了解决这个问题我使用了MybatisPlus中的JacksonTypeHandler处理器所以我定义了单独实体类来与info字段的属性匹配, @Data public class UserInfo { private Integer age; private String intro; private String gender; } 然后我将User类的info字段修改为UserInfo类型,并声明类型处理器 @Data @TableName(autoResultMap = true)//开启自动映射 public class User { private Long id; private String username; private String password; private String phone; @TableField(typeHandler = JacksonTypeHandler.class) private UserInfo info; private UserStatus status; private Integer balance; private LocalDateTime createTime; private LocalDateTime updateTime; } 为了让页面返回的结果也以对象格式返回,修改UserVO中的info字段: @Data @ApiModel(description = "用户VO实体") public class UserVO { @ApiModelProperty("用户id") private Long id; @ApiModelProperty("用户名") private String username; @ApiModelProperty("详细信息") private UserInfo info; @ApiModelProperty("使用状态(1正常 2冻结)") private UserStatus status; @ApiModelProperty("账户余额") private Integer balance; @ApiModelProperty("用户的收获地址") private List address; } 然后开始运行,好家伙直接报错 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController' defined in file [F:\springcloud\mp-demo\target\classes\com\itheima\mp\controller\UserController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'baseMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [F:\springcloud\mp-demo\target\classes\com\itheima\mp\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.io.IOException: Failed to parse mapping resource: 'file [F:\springcloud\mp-demo\target\classes\mapper\IUserService.xml]' 我把User中的info改回String类型,不报错,但是查询出错500因为跟用户VO实体UserVO中的info对不上,总的来说就是User中的info不能用UserInfo,一运行就报错,写进去啥事没有