使用hql动态创建对象问题

news/2024/7/3 2:09:00

      前段时间由于需求要添加报表数据,调整ireport后,打印pdf文件出现数据错位的情况,调试发现不是ireport问题,就查看了后台传送的数据,最后发现传送的对象属性值已经就是错位的,那就是获取对象时出的问题,查看了查询语句,发现问题了,查询时使用hql动态创建对象,但查询语句中对象的属性顺序跟该对象带参构造函数中传参的顺序没有一一对应,也就是,比如以下对象User:

public class User {priavte Integer id;private String name;private String age;private String mobile;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getAge() {return age;}public void setAge(String age) {this.age= age;}public String getMobile() {return mobile;}public void setMobile(String mobile) {this.mobile= mobile;}public User(){} public User(Integer id,String name,String age,String mobile){this.id= id;this.name=name;this.age=age;this.mobile=mobile;}
}        

 hql查询动态创建对象时对象参数必须是:select new User(id,name,age,mobile) from User;  顺序必须一致,查询结果数据才不会错位。

转载于:https://www.cnblogs.com/Mrshuang11/p/8880712.html


http://lihuaxi.xjx100.cn/news/237059.html

相关文章

电子邮件传输的内容_电子邮件标题中有什么内容,为什么要关注?

电子邮件传输的内容Ever gotten a spam or phishing message from an email address you didnt recognize? Maybe someone offered you a free trip, asked you to send them bitcoin in exchange for personal photos, or just sent you an unwanted marketing email? 是否曾…

python+selenium百度贴吧自动签到

#-*- coding:utf-8 -*- from selenium import webdriver import time import os import random from selenium.webdriver.common.action_chains import ActionChainsbrowser webdriver.Chrome()# 最大等待加载完的时间 max_loading 600 # 延时随机n秒执行 wait_time random.…

区块链还能赚钱吗 区块链挖矿赚钱吗

链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 区块链有多火,连我母上都知道这个词,身边很多人也都向笔者咨询这个东西。 其实他们真实的想法是,想知道这东西到…

sql算术运算符_SQL运算符教程–按位,比较,算术和逻辑运算符查询示例

sql算术运算符At its core, the internet and all its applications are just data.互联网及其所有应用程序的核心只是数据。 Every email, tweet, selfie, bank transaction, and more is just data sitting in a database somewhere.每封电子邮件,推文&#xff0…

[专业亲测]Ubuntu16.04安装Nvidia显卡驱动(cuda)--解决你的所有困惑【转】

本文转载自: 因为要做毕设需要安装caffe2,配置cuda8.0,但是安装nvidia驱动真的是把我难倒了,看了很多篇博文都没有效果,现在我自己重新总结了下几种 安装方法(亲测有效),希望能帮到大…

go语言有哪些优势

链客,专为开发者而生,有问必答! 此文章来自区块链技术社区,未经允许拒绝转载。 1、学习曲线容易 Go语言语法简单,包含了类C语法。因为Go语言容易学习,所以一个普通的大学生花几个星期就能写出来可以上手的…

div 相同属性提取

把样式名或id写在一起&#xff0c;用逗号隔开 <!DOCTYPE html><html lang"en"><head> <meta charset"UTF-8"> <title>信息详情</title> <style type"text/css"> #box-1, #box-2, #box…

关键字this引用

要点提示&#xff1a; 关键字this引用独享自身。他也可以在构造方法内部调用另一个类的其他构造方法。 关键字this是指向调用对象本身的引用名。可以用this关键字引用对象的实例成员。 复制代码 例如&#xff1a;下面a的代码使用this来显示地引用独享的radius以及调用他的getAr…