最近有很多朋友用到select new 方法。下面我给大家举个简单的例子。

定义类:

public class TycoonRow implements Serializable {

    private static final long serialVersionUID = -8902581963250812345L;

    private int id;

    private String name;

    public TycoonRow(int id, String name) {
        super();
        this.id = id;
        this.checkNo = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

 

    public int getName() {
        return name;
    }

    public void setName(int name) {
        this.name= name;
    }


执行sql语句。

select new cn.dbdh.new.TycoonRow(tb1.id as id,ch.tb2 as name) "
                            + "from table_1 tb1,table_2 tb2 where tb1.id=tb2.id

说明:hql语句中的列名必须和实体类中的变量一一对应并且名称相同,顺序相同。希望对需要的朋友给与帮助

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2021-12-16
  • 2021-10-06
  • 2022-12-23
  • 2021-12-19
猜你喜欢
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-01-31
  • 2022-03-02
  • 2021-11-23
相关资源
相似解决方案