标签:ssid htm style app 1.3 tar city code resultmap
1. 一对一关系
1.1 entiry
1.1.1 TPersonInfo.java
package com.blueStarWei.entity; public class TPersonInfo { private Integer id; private String name; private Integer age; private Address address; //setter & getter @Override public String toString() { return "TPersonInfo [id=" + id + ", name=" + name + ", age=" + age + ", address=" + address + "]"; } }
1.1.2 Address.java
package com.blueStarWei.entity; public class Address { private int id; private String country; private String city; //setter & getter @Override public String toString() { return "Address [country=" + country + ", city=" + city + "]"; } }
1.2 Maper
1.2.1 PersonAddressMapper.java
package com.blueStarWei.mappers; import java.util.List; import com.blueStarWei.entity.TPersonInfo; public interface PersonAddressMapper { List<TPersonInfo> findAllWithAddress(); }
1.2.2 PersonAddressMapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.blueStarWei.mappers.PersonAddressMapper"> <select id="findAllWithAddress" resultMap="personResult"> SELECT t1.*,t2.* FROM t_person_info t1 JOIN t_address t2 ON t2.id = t1.addressid </select> <resultMap type="TPersonInfo" id="personResult"> <id property="id" column="id"/> <result property="name" column="name"/> <result property="age" column="age"/> <association property="address" resultMap="addressResult"/> </resultMap> <resultMap type="Address" id="addressResult"> <id property="id" column="id"/> <result property="country" column="country"/> <result property="city" column="city"/> </resultMap> </mapper>
1.3 配置信息等,请参考 myBatis之入门示例
标签:ssid htm style app 1.3 tar city code resultmap
原文地址:https://www.cnblogs.com/BlueStarWei/p/9160437.html