如何使用JSTL sql:query访问重复的列名? [英] How to access duplicate column names with JSTL sql:query?

查看:105
本文介绍了如何使用JSTL sql:query访问重复的列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,这个

    <sql:query dataSource="${ds}" sql="select user.id, user.name as userName, city, state, country, country.name as countryName, latitude, longitude, ip, last_visit from user, country where user.country = country.id order by last_visit desc limit 100" var="result"/>
    <c:forEach var="col" items="${result.columnNames}">
        ${col}, 
    </c:forEach>

产生

id, name, city, state, country, name, latitude, longitude, ip, last_visit,

哪个错了。我专门重命名了查询中的列。我不知道它是如何找到原始字段名称的。那么如何访问user.name的值呢? $ {row.userName} 不起作用。

Which is wrong. I specifically renamed the columns in the query. I don't know how it found the original field name. So how can I access the value of user.name? ${row.userName} doesn't work.

我正在使用JSTL jstl-1.2.2。

I'm using JSTL jstl-1.2.2.

推荐答案

不确定这是否有用,但我读过使用别名并不总是能正常工作。我见过一个可能的替代方案:

Not sure if this will help, but I've read that using aliases will not always work correctly. A possible alternative I've seen:

 <sql:query dataSource="${ds}" sql="select user.id, concat(user.name,'') as userName, city, state, country, concat(country.name,'') as countryName, latitude, longitude, ip, last_visit from user, country where user.country = country.id order by last_visit desc limit 100" var="result"/>
    <c:forEach var="col" items="${result.columnNames}">
        ${col}, 
    </c:forEach>

希望这会有所帮助。祝你好运。

Hope this helps. Good luck.

这篇关于如何使用JSTL sql:query访问重复的列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆