mybatis中sql查询为null问题

1、如果

ServerConfigMapper中对应的xml为:

列名为 IP 和 PORT

<select  id="selectConfig" resultMap="BaseResultMap">

 select S.IP, s.port,  'server' as type, s.platformid
   from desk d, SERVERCONFIG s
   where D.EXCHID in ('0', '2')
  。。。。。。。。。。。
   
</select>

如果想采用本地IP 和 端口port,例如

列名为:127.0.0.1 和 1234

<select  id="selectConfig" resultMap="BaseResultMap">

 select '127.0.0.1', 1234,  'server' as type, s.platformid
   from desk d, SERVERCONFIG s
   where D.EXCHID in ('0', '2')
    。。。。。。。。。。。
   
</select>

此时采用mybatis,如下,此时获取得到的Ip=null ,port也是null。因为第一个查询,列名为 IP 和 PORT,但 第二个为 127.0.0.1 和 1234,故获取到的ip 和 port值为null,null

SqlSession sqlSession = SessionFactoryUtil.getSession();

configList = new ArrayList<ServerConfig>();
ConfigMapper mapper = sqlSession.getMapper(ConfigMapper.class);
configList = mapper.selectConfig(type);

正确写法:'127.0.0.1' as IP, 1234 as port

<select  id="selectConfig" resultMap="BaseResultMap">

 select '127.0.0.1' as IP, 1234 as port,  'server' as type, s.platformid
   from desk d, SERVERCONFIG s
   where D.EXCHID in ('0', '2')
    。。。。。。。。。。。
   
</select>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值