我想在hibernate中对数据进行降序排序, 但根本不工作,
这是我的代码,
@SuppressWarnings("unchecked")
@Override
public List<MPNValas> listAllMPNValas() throws Exception{
DetachedCriteria criteria = DetachedCriteria.forClass(MPNValas.class);
criteria.addOrder(Order.desc("ID"));
List<MPNValas> mpnvalasList = getHibernateTemplate().findByCriteria(criteria);
return mpnvalasList;
}
这是我的控制器,
@RequestMapping("/admin/mpn-valas.html")
public ModelAndView listMPNValas(ModelMap model)throws Exception
{
User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String sessionUser = user.getUsername();
try{
UserAdmin dataUser = userService.get(sessionUser);
model.addAttribute("userData", dataUser);
} catch(Exception e){
e.printStackTrace();
}
ModelAndView mav = new ModelAndView("mpnvalas");
List<MPNValas> mpnvalas = mpnvalasService.listAllMPNValas();
mav.addObject("mpnvalas", mpnvalas);
return mav;
}
这是班级,
package prod.support.model.gwprod;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="LOOKUP")
public class MPNValas {
private Integer ID;
private String TIPE;
private String KODE_PERUSAHAAN;
private String CODE;
private String NAME;
private String VALUE;
@Id
@Column(name="ID", unique=true, nullable=false)
public Integer getID() {
return ID;
}
public void setID(Integer ID) {
this.ID = ID;
}
@Column(name="TIPE")
public String getTIPE() {
return TIPE;
}
public void setTIPE(String TIPE) {
this.TIPE = TIPE;
}
@Column(name="KODE_PERUSAHAAN")
public String getKODE_PERUSAHAAN() {
return KODE_PERUSAHAAN;
}
public void setKODE_PERUSAHAAN(String KODE_PERUSAHAAN) {
this.KODE_PERUSAHAAN = KODE_PERUSAHAAN;
}
@Column(name="CODE")
public String getCODE() {
return CODE;
}
public void setCODE(String CODE) {
this.CODE = CODE;
}
@Column(name="NAME")
public String getNAME() {
return NAME;
}
public void setNAME(String NAME) {
this.NAME = NAME;
}
@Column(name="VALUE")
public String getVALUE() {
return VALUE;
}
public void setVALUE(String VALUE) {
this.VALUE = VALUE;
}
/**
* @param args
*/
}
这是数据列表
我错过了什么?
任何帮助都会很愉快:))
答案 0 :(得分:3)
您没有遗漏任何内容,只需注意 desc 方法的参数区分大小写,并且应该与要排序的属性名称匹配。
floatingmenu.getAddButton().setColorNormal(...);