Mybatis注解@Select结合@Results使用

 

该方式是否可以解决不同数据库字段别名的不同写法问题,如果是多表联查(多表有命名一样的字段), @Result可以准确定位sql中具体相关表的字段呢?回家测试一下!!!

public interface TestMapper {

    @Select("SELECT " +
            "t1.APPLY_NO," +
            "t1.CARD_IS_LONG_VALID," +
            "t1.SPELL_NAME ,"+
            "t1.EDUCATION  , " +
            "t1.MARITAL_STATUS "+
            "FROM " +
            "identity_info t1 " +
            "WHERE " +
            " t1.apply_no  = #{applyNo}")
    @Results({
            @Result(property = "applyNo", column = "APPLY_NO"),
            @Result(property = "cardIsLongValid", column = "CARD_IS_LONG_VALID"),
            @Result(property = "spellName", column = "SPELL_NAME"),
            @Result(property = "education", column = "EDUCATION"),
            @Result(property = "maritalStatus", column = "MARITAL_STATUS")

    })
    Map queryBasicInfo(Map paramMap);

    @SelectProvider(type = SelectBasicInfo.class,method = "selectBasicInfo")
    List<Map> selectBasicInfo(Map paramMap);
    public class SelectBasicInfo{
        public  String selectBasicInfo(){
            return new SQL(){
                {
                    SELECT("APPLY_NO as applyNo");
                    SELECT("CARD_IS_LONG_VALID  as cardIsLongValid");
                    SELECT("SPELL_NAME as spellName   ");
                    SELECT("EDUCATION as education   ");
                    SELECT("MARITAL_STATUS as maritalStatus   ");
                    FROM("identity_info");
                    WHERE("apply_no = #{applyNo} ");
                    WHERE("MARITAL_STATUS = '1' ");
                    ORDER_BY("created_date desc");
                }
            }.toString();
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值