大部分现实应用中我们并不需要把数据库中的整行数据都拉出来, 所以要做扩展结果集
笔记: 在实际项目过程中, 先用逆向工程自动生成, 然后再做扩展结果集来满足大部分的现实需要
本节内容应该注意扩展结果集的命名方式
创建一个扩展类ShopCustom, (这样命名可以和Shop在项目树里面排列在一起)
1. package io.github.coinsjack.pojo; 2. 3. public class ShopCustom extends Shop { 4. 5. private String shopName; 6. private String shopDesc; 7. 8. public ShopCustom() { 9. }
创建一个mapper接口 ShopMapperCustom
1. package io.github.coinsjack.dao; 2. 3. import io.github.coinsjack.pojo.ShopCustom; 4. 5. public interface ShopMapperCustom { 6. 7. ShopCustom getShopById(Integer id);
创建对应的映射文件
1. <?xml version="1.0" encoding="UTF-8" ?> 2. <!DOCTYPE mapper 3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5. 6. 7. <mapper namespace="io.github.coinsjack.dao.ShopMapperCustom"> 8. 9. <cache/>
1. 2. <!DOCTYPE mapper 3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5. 6. 7. 8. 9.
测试
1. <?xml version="1.0" encoding="UTF-8" ?> 2. <!DOCTYPE mapper 3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5. 6. 7. <mapper namespace="io.github.coinsjack.dao.ShopMapperCustom"> 8. 9. <cache/>
结果
1. <?xml version="1.0" encoding="UTF-8" ?> 2. <!DOCTYPE mapper 3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5. 6. 7. <mapper namespace="io.github.coinsjack.dao.ShopMapperCustom"> 8. 9. <cache/>