天天看点

MyBatis使用别名

  • 配置application.yml
mybatis:
  mapper-locations: classpath:/mybatis/mapper/*.xml
  type-aliases-package: com.zhaofeng.deliverymanagement.pojo
  configuration:
    map-underscore-to-camel-case: true
           
  • 实体类没有getter和setter方法,可能会出现以下错误
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class com.zhaofeng.deliverymanagement.pojo.UserPojo and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.zhaofeng.deliverymanagement.common.JsonResult["data"]->java.util.ArrayList[0])
           
  • 为需要使用别名的实体类加上注解,如:
  • xml文件中可以直接使用类名
<!-- 用户详细信息 -->
<resultMap id="UserDetailMap" type="UserPojo">
           

继续阅读