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>