gpt4 book ai didi

java - 如何在我的 Spring WebFlow 项目中向这个 hibernate 调用添加排序

转载 作者:太空宇宙 更新时间:2023-11-04 08:04:05 24 4
gpt4 key购买 nike

如何在我的 Spring WebFlow 项目中向此 hibernate 调用添加排序。我正在开发一个 Spring Webflow 项目,我必须在以下调用中添加排序。

@SuppressWarnings("unchecked")
public List<School_lookupModel> getSelectableSchools(String b) {
String myLike = b + "%";
Session mySession = sessionFactory.getCurrentSession();
List<School_lookupModel> mySchools = (List<School_lookupModel>) mySession
.createCriteria(School_lookupModel.class)
.add(Restrictions.like("school", myLike)).list();

return mySchools;
}

我尝试了以下代码,但它无法构建:

public List<School_lookupModel> getSelectableSchools(String b) {

String myLike = b + "%";

Session mySession = sessionFactory.getCurrentSession();

List<School_lookupModel> mySchools = (List<School_lookupModel>) mySession
.createCriteria(School_lookupModel.class)
.add(Restrictions.like("school", myLike)
.addOrder(Order.asc("school"))).list();


return mySchools;
}

有人可以告诉我如何在第一次调用中添加订单吗?谢谢,我在构建中遇到以下两个错误:

语法错误,请插入“)”完成和SimpleExpression 类型的 addOrder(Order) 方法未定义

这是我的类(class):

package org.xxx.schoolvisit.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.annotations.OrderBy;

@Entity
@Table(name = "school")
public class School_lookupModel {

@Override
public String toString() {
return "School_lookupModel [school=" + school + ", school_name="
+ school_name + ", region=" + region + ", district=" + district
+ ", getSchool()=" + getSchool() + ", getSchool_name()="
+ getSchool_name() + ", getRegion()=" + getRegion()
+ ", getDistrict()=" + getDistrict() + ", getClass()="
+ getClass() + ", hashCode()=" + hashCode() + ", toString()="
+ super.toString() + "]";
}

@Id
@Column(name = "school")
private String school;

@Column(name = "school_name")
private String school_name;

@Column(name = "region")
private String region;

@Column(name = "district")
private String district;

public String getSchool() {
return school;
}

public void setSchool(String school) {
this.school = school;
}

public String getSchool_name() {
return school_name;
}

public void setSchool_name(String school_name) {
this.school_name = school_name;
}

public String getRegion() {
return region;
}

public void setRegion(String region) {
this.region = region;
}

public String getDistrict() {
return district;
}

public void setDistrict(String district) {
this.district = district;
}


}

最佳答案

您在此级别缺少括号

  .add(Restrictions.like("school", myLike)
.addOrder(Order.asc("Name")).list();

像这样

 .add(Restrictions.like("school", myLike)
.addOrder(Order.asc("Name"))).list();

您遇到的错误是什么?看这里的例子: http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html看起来你的语法是正确的,它一定与O/R映射有关,你是否使用注释将类映射到表或xml文件?您有一个名为“姓名”的字段吗?或者您有姓名或姓名?你尝试过这些吗?

关于java - 如何在我的 Spring WebFlow 项目中向这个 hibernate 调用添加排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12356686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com