忆梦迪 2021-05-29 18:45 采纳率: 50%
浏览 23
已采纳

初学mybatis的一个小问题

这是一个StudentMapper的xml配置文件

数据库里phone是VARCHAR类型xxx-xxx-xxx这种的,我想把phone根据“-”分割然后映射给Student里的phone但是做不到

这个能达到吗

<resultMap type="Student" id="StudentWithAddressResult">
    <id property="studId" column="id" />
       <result property="name" column="name" />
       <result property="email" column="email" />
        <result property="dob" column="dob" />
        <!-- 重点下面这一行 -->
        <result property="phone" column="phone" />
       <association property="address" javaType="Address">
            <id property="addrId" column="addr_id"/>
            <result property="street" column="street"/>
            <result property="city" column="city"/>
            <result property="state" column="state"/>
            <result property="zip" column="zip"/>
            <result property="country" column="country"/>
        </association>
</resultMap>

这是Student类

    private Integer studId;
    private String name;
    private String email;
    private Date dob;
    private PhoneNumber phone;
    //private String phone;
    private Address address;

    public Student() {}

这是PhoneNumber类

    private String countryCode;
    private String stateCode;
    private String number;

    public PhoneNumber() {}
  • 写回答

1条回答 默认 最新

  • 编号灬9527 2021-05-29 18:49
    关注

    完全ojbk,自己去实现TypeHandler就行了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)