怎么取如何取出list中的数据据

多表联合查询后的结果的结果放入list里,如何拿出来 - ITeye问答
DaoImpl代码:
public List findstudentidList(int i){
String hql = "from User u,TTopic t,Log l where u.id = ? and u.name = t.teachername and t.topicid = l.topicid and t.isfinaltopic = true and l.isdroped = true";
return this.getHibernateTemplate().find(hql,i);
Action代码:
list = new ArrayList();
list = this.service.findListstudentid(user.getId());
for (int i = 0; i & list.size(); i++){
Object[] arr = (Object[])list.get(i);
System.out.println("a = "+arr[0].toString());
System.out.println("b = "+arr[1].toString());
System.out.println("c = "+arr[2].toString());
控制台怎么输出这些:
a = gdms.bean.User@1298826
b = gdms.bean.TTopic@1a99836
c = gdms.bean.Log@148083b
a = gdms.bean.User@1298826
b = gdms.bean.TTopic@1f31ad9
c = gdms.bean.Log@18b4ccb
问题补充:yangleilt 写道String hql = "from User u,TTopic t,Log l where u.id = ? and u.name = t.teachername and t.topicid = l.topicid and
这句话里面User u,表示了查出来的是对象
list = new ArrayList();
list = this.service.findListstudentid(user.getId());
for (int i = 0; i & list.size(); i++){
Object[] arr = (Object[])list.get(i);
System.out.println("a = "+arr[0].toString());
System.out.println("b = "+arr[1].toString());
System.out.println("c = "+arr[2].toString());
将对象取出来放到list里面 然后又一一读取放到object的数据里面 这一步有点多余! 为何不直接读取list 从list里面取呢?
arr[0]取到的还是对象 所以打印出来的是内存地址了!
我也想从list里面取数据呀,但是不知道怎么取,可不可以指点我一下。谢谢!
问题补充:yangleilt 写道DaoImpl代码:
public List findstudentidList(int i){
String hql = "from User u,TTopic t,Log l where u.id = ? and u.name = t.teachername and t.topicid = l.topicid and t.isfinaltopic = true and l.isdroped = true";
return this.getHibernateTemplate().find(hql,i);
Action代码:
list = new ArrayList();
list = this.service.findListstudentid(user.getId());
for (int i = 0; i & list.size(); i++){
Object[] arr = (Object[])list.get(i);
System.out.println("a = "+arr[0].toString());
System.out.println("b = "+arr[1].toString());
System.out.println("c = "+arr[2].toString());
public List findstudentidList(int i){...

list = this.service.findListstudentid(user.getId());
中的findstudentidList& findListstudentid 有问题吗1你能不能把正确的代码 贴出来呀
我用的是SSH框架开发的项目,跟这有关的代码,我都已经贴出来了,没有问题,而且按照”时之刃“程序员的方法能拿到正确的值了,我想问一下,怎么直接读取list 从list里面取值,因为我要把这些值传到JSp页面上去。谢谢!
问题补充:时之刃 写道Hibernate取到的是未转型的Object,先转型,然后取bean中的属性值就可以了。例如:((User)arr[0]).getUserName()
您好。谢谢你的帮助,我已经拿到正确的值了。
采纳的答案
如果说 根据多表查询只是查询的条件不同 而显示的数据还是一个表中的数据 这样的话 查询语句按SQL语句一样的写法 如果说 查询出数据要分别显示几个表中的信息的话 这个很麻烦 新建一个实体类 实体类的属性包含要显示数据的字段 然后只能按照原始的数据库连接读取数据 一个个的赋值 添加到List中
DaoImpl代码:
public List findstudentidList(int i){
String hql = "from User u,TTopic t,Log l where u.id = ? and u.name = t.teachername and t.topicid = l.topicid and t.isfinaltopic = true and l.isdroped = true";
return this.getHibernateTemplate().find(hql,i);
Action代码:
list = new ArrayList();
list = this.service.findListstudentid(user.getId());
for (int i = 0; i & list.size(); i++){
Object[] arr = (Object[])list.get(i);
System.out.println("a = "+arr[0].toString());
System.out.println("b = "+arr[1].toString());
System.out.println("c = "+arr[2].toString());
public List findstudentidList(int i){...

list = this.service.findListstudentid(user.getId());
中的findstudentidList& findListstudentid 有问题吗1你能不能把正确的代码 贴出来呀
String hql = "from User u,TTopic t,Log l where u.id = ? and u.name = t.teachername and t.topicid = l.topicid and
这句话里面User u,表示了查出来的是对象
list = new ArrayList();
list = this.service.findListstudentid(user.getId());
for (int i = 0; i & list.size(); i++){
Object[] arr = (Object[])list.get(i);
System.out.println("a = "+arr[0].toString());
System.out.println("b = "+arr[1].toString());
System.out.println("c = "+arr[2].toString());
将对象取出来放到list里面 然后又一一读取放到object的数据里面 这一步有点多余! 为何不直接读取list 从list里面取呢?
arr[0]取到的还是对象 所以打印出来的是内存地址了!
Hibernate取到的是未转型的Object,先转型,然后取bean中的属性值就可以了。例如:((User)arr[0]).getUserName()
已解决问题
未解决问题Freemarker中如何遍历List -
- ITeye技术网站
博客分类:
Freemarker中如何遍历List(附源码)
关键词(Keyword):Freemarker,Freemarker遍历list
在Freemarker应用中经常会遍历List获取需要的数据,并对需要的数据进行排序加工后呈现给用户。那么在Freemarker中如何遍历List,并对List中数据进行适当的排序呢?
通过下文的介绍,相信您一定会找到答案。
Freemarker中list指令简单介绍
要想在Freemarker中遍历list,必须通过使用list指令,即&#list sequence as item&…&/#list&
sequence是集合(collection)的表达式,item是循环变量的名字,不能是表达式。
当在遍历sequence时,会将遍历变量的值保存到item中。
举个例子说明吧:
&#list userList as user&
userList中封装了很多个User对象,我们在遍历userList时候,会将遍历的User对象的值,保存到上述的user变量中。那么在取值时,我们可以通过${user.userName }来获取User对象的userName属性值。
List指令还隐含了两个循环变量:
item_index:当前迭代项在所有迭代项中的位置,是数字值。
item_has_next:用于判断当前迭代项是否是所有迭代项中的最后一项。
注意:在使用上述两个循环变量时,一定要将item换成你自己定义的循环变量名,item其实就是前缀罢了。
例如,如果你使用&# list list as l&..&/#list&定义,那么就要使用l_index,l_has_next。
在循环过程中,如果您想跳出循环,那么可以使用结合break指令,即&#break&来完成。
Freemarker中对List进行排序
通常我们的排序操作都是通过DAO层来实现的,如果我们想随时更改我们的排序,那么就必须修改我们的DAO层代码,确实不方便。但Freemarker为我们提供了这样的排序方法,解决了这个问题。
sort升序排序函数
sort对序列(sequence)进行排序,要求序列中的变量必须是:字符串(按首字母排序),数字,日期值。
&#list list?sort as l&…&/#list&
sort_by函数
sort_by有一个参数,该参数用于指定想要排序的子变量,排序是按照变量对应的值进行排序,如:
&#list userList?sort_by(“age”) as user&…&/#list&
age是User对象的属性,排序是按age的值进行的。
reverse降序排序函数
&#list list? reverse as l&…&/#list&。reverse使用同sort相同。reverse还可以同sort_by一起使用
如:想让用户按年龄降序排序,那么可以这个样写&#list userList?sort_by(“age”)?reverse as user&…&/#list&
Freemarker如何遍历List实例应用
创通过上面的介绍,相信您已经对Freemarker如何遍历List有了了解,那么我们就废话少说,开始做一个应用吧。
public class User{
(省略set和get方法)
&#--Freemarker遍历list--&
简单遍历list:
&#list userList as user&
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#--Freemarker遍历list并应用list隐含变量item_index--&
item_index使用:
&#list userList as user&
第${user_index+1}个用户
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#--Freemarker遍历list并应用list隐含变量item_has_next--&
item_has_next,size使用:
&#list userList as user&
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#if !user_has_next&
共有${userList?size}最后一个用户是:${user.userName}
&#--Freemarker遍历list并按用户年龄升序排序--&
按用户年龄升序排序:
&#list userList?sort_by("age") as user&
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#--Freemarker遍历list并按用户年龄降序排序--&
按用户年龄降序排序:
&#list userList?sort_by("age")?reverse as user&
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#--Freemarker遍历list当用户年龄大于21岁时,停止输出--&
list中应用break:
&#list userList?sort_by("age")?reverse as user&
用户名:${user.userName}
码:${user.userPassword}
龄: ${user.age}
&#if (user.age&21) &
ClientTest类
public class ClientTest{
public static List&User& initUserList(){
User user1=new User();
user1.setUserName("张三");
user1.setUserPassword("123");
user1.setAge(20);
User user2=new User();
user2.setUserName("李四");
user2.setUserPassword("123");
user2.setAge(22);
User user3=new User();
user3.setUserName("王五");
user3.setUserPassword("123");
user3.setAge(21);
List&User& list=new ArrayList&User&();
list.add(user1);
list.add(user2);
list.add(user3);
public static void main(String[] args){
List&User& list=ClientTest.initUserList();
Map&String,Object& root=new HashMap&String,Object&();
root.put(“userList”,list);
FreeMarkertUtil.analysisTemplate(“user.ftl”,”UTF-8”,root);
//FreeMarkUtil类可以参考我上传得源码。
好了,到这里程序就结束了,您可以运行ClientTest类来查看输出结果了。
希望通过本文的介绍,可以让您对FreeMarker如何遍历List有一个清楚的了解。
浏览 18865
浏览: 186045 次
来自: 乌鲁木齐
总结的不错。
只是取前几条数据吧,不用这么复杂。循环,[#list coco ...苹果/安卓/wp
积分 109, 距离下一级还需 36 积分
权限: 自定义头衔
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡下一级可获得
道具: 匿名卡
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
开心签到天数: 40 天连续签到: 1 天[LV.5]常住居民I
某一个list对象里面有一串数据。
[1] 116.631 124.119&&44.389&&52.56089
[8]&&78.929 126.996 121.633&&94.53887
[15] 148.027&&54.713&&42.317&&66.33335
[22] 130.564 125.283 141.363&&73.98447
[29]&&54.510&&50.496&&98.719 160.34259
[36] 129.122 112.812&&73.321&&41.22968
[43]&&38.156 104.878 160.076 167.85461
[50] 153.487&&78.895&&40.386&&70.54365
[57]&&80.009 156.282 120.562&&95.23341
[64]&&59.129&&42.978&&78.697&&93.68070
[71] 158.384 151.394 120.610&&44.05572
[78]&&48.749&&53.742 118.956 151.27539
我想用这些数据来画时间序列。
& lts&-ts(l,frequency=12,start=2002)
& plot(lts)
错误于xy.coords(x, NULL, log = log) :
&&(串列)对象不能强制改变成'double'种类
这种情况下我改如何处理啊?
载入中......
首先要把数据改成时间序列类型
I&-as.ts(I)
总评分:&学术水平 + 1&
热心指数 + 1&
信用等级 + 1&
无限扩大经管职场人脉圈!每天抽选10位免费名额,现在就扫& 论坛VIP& 贵宾会员& 可免费加入
加入我们,立即就学扫码下载「就学」app& Join us!& JoinLearn&
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
京ICP证090565号
京公网安备号
论坛法律顾问:王进律师怎么从list&Vo& 中取出数据_怎么编写可以将所有结构类型的链表存入文件的函数_数组和链表,该如何处理__脚本百事通
稍等,加载中……
^_^请注意,有可能下面的2篇文章才是您想要的内容:
怎么从list&Vo& 中取出数据
怎么编写可以将所有结构类型的链表存入文件的函数
数组和链表,该如何处理
怎么从list&Vo& 中取出数据
如何从list&Vo& 中取出数据如何从list&Vo& 中取出数据:List&Vo& list=new List&Vo&(); //Vo 是一个实体类,里面有ID,name, comm,三个实体。我把数据放进list 之后,我想再从list 里面读取出来 ,应该怎么写代码啊。求详细代码。。举个例子。。。有用的都有分------解决方案--------------------foreach或for循环读取foreach(Vo
v in list){ v.ID}不知你具体想做些什么?
------解决方案--------------------遍历list,如楼上督察说的
------解决方案--------------------C# code
public class MainClass
class Program
static void Main(string[] args)
List&Vo& list = new List&Vo&();
Vo vo1 = new Vo();
vo1.ID = 1;
vo1.name = "aa";
m = "comaa";
list.Add(vo1);
Vo vo2 = new Vo();
vo2.ID = 2;
vo2.name = "bb";
m = "combb";
list.Add(vo2);
//------------上面是添加------------
foreach (Vo vo in list)
Console.WriteLine(vo.ID + "-" + vo.name + "-" + vo.comm);
for (int i = 0; i & list.C i++)
Console.WriteLine(list[i].ID + "-" + list[i].name + "-" + list[i].comm);
Console.ReadLine();
/// &summary&
/// 你的实体类
/// &/summary&
public class Vo
public int ID { }
public string name { }
public string comm { }
------解决方案--------------------取list中第n个实体的数据:list[n-1].ID,list[n-1].name,
list[n-1].comm
------解决方案--------------------var result = list.Select(x =& x.name); //取名字集合var result1 = list.Select(x =& new { x.ID, x.name }); //取得id和名字两列var result2 = result1.Take(10); //取得 result1 前10条记录var result3 = list.Max(x =& x.ID); //取得 ID 最大值var result4 = list.Where(x =& x.name == "xxx"); //取得名字为xxx的记录...
------解决方案--------------------foreach(var item in list){}妥妥的
怎么编写可以将所有结构类型的链表存入文件的函数
如何编写可以将所有结构类型的链表存入文件的函数?想将链表存入文件,再读入内存形成链表,对于某个类型的链表可以实现,现在我想实现一个函数可以将所有类型的链表存入文件的函数,那么需要将这个链表的结构类型告诉这个函数。如果是C++可以使用重载来完成,但是C里面没有重载,我怎么把结构类型传给函数呢?期待高手解答。------解决方案--------------------c++也不能实现吧,即使你写文件可以实现,但读取是肯定没法万全区分的.
如果不怕麻烦可以这样
所有的结构体要这样定义:在结构体的头4个字节存放改结构体的大小,在4个字节存放指向下一个结构体的指
针,再往后存放有效数据,这样,在往文件内写时,读时都可以实现了.
当然,这种方法在读取时如果你的结构体如果大小有相同的时候就会区别不开了. ------解决方案--------------------应该可以的,定义结构如下:
typedef unsigned char U8;
typedef char S8;
typedef struct A_t A;
typedef struct B_t B;
typedef int (*read_func)(void* data,int len);
typedef int (*write_func)(void* data,int len);
typedef struct i_t
int t_//totol size
void*//stuct data
read_func read_f;//read function
write_func write_f;//write function
typedef struct A_t
typedef struct B_t
U8* data1;
U8* data2;
}B; ------解决方案--------------------void *
------解决方案--------------------struct node {
uchar payload[1];
parent, left, right全部是相对于0的偏移量, paylaod真实的数据
------解决方案--------------------用回调函数做
C库里有的qsort函数就是这样的
qsort可以对任意的数组类型进行排序,做法就是调用的时候传入一个回调函数。
------解决方案--------------------长见识了~MARK!
数组和链表,该如何处理
数组和链表以前很喜欢用链表,发现链表有很多优点可是最近发现链表似乎不如数组比如以前想动态分配地址就用链表,后来发现数组也能动态分配但是遇到需要追加地址的情况就又只能使用链表,但后来发现使用alloc()也可以追加数组元素个数所以我纳闷了,链表要加一个指针,所以链表所占的空间势必比数组大,使用起来也没数组方便。以前所认为的链表对于数组的两个优点现在发现数组做得更好,而且链表比数组更占空间请各位告诉我,链表有什么存在的必要呢?------解决方案--------------------链表的空间不必连续,所以添加或者删除都比较方便。只是查找比较麻烦点。
------解决方案--------------------谁也没有说链表好是因为它可以动态分配内存啊?!你说数组使用方便,那么它在哪方面方便,哪方面又不方便呢?!空间占用也不是决定因素,只要需要,就可以占用更多空间,只要你设计合理即可。链表的特点在于可以在中间插入和删除,这点数组是无法比拟的------解决方案--------------------以前想动态分配地址就用链表,后来发现数组也能动态分配
你删除数组中间一个数据,然后保持连续性,可以吗?链表的用处大者呢。
------解决方案--------------------各有千秋,建议LZ好好看看数据结构中有序表跟链表的特点.
------解决方案--------------------数组的动态分配是什么?难道数组可以预先不给它分配多少空间?就算上面提到的2点数组也能实现,但数组对内存的空间是连续的,碰到一个程序要分配比较大的空间,此时内存连续的空间又没这么大,但内存的总空间是够大了的,所以此时用链表还能实现,以不至于程序结束。
------解决方案--------------------排个序,删个元素什么的,就知道区别了
如果您想提高自己的技术水平,欢迎加入本站官方1号QQ群:&&,&&2号QQ群:,在群里结识技术精英和交流技术^_^
本站联系邮箱:}

我要回帖

更多关于 list取最后一条数据 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信