我需要通过枚举类型从数据库中获取数据。 我有以下枚举:冬眠通过枚举类型查询
public enum ShopType {
VANS("VANS"), ATTICUS("ATTICUS"), FAMOUS("FAMOUS")
ShopType(String label) {
this.label = label;
}
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
在我的DAO类我有方法,它通过选择的类型上jsp
页面返回一个对象名单。在jsp
页面我发送选定的值,如String
,是不是?
那怎么看我的方法
@Transactional
public List<Shop> findByType(String type) {
return sessionFactory.getCurrentSession().createQuery("from Shop where type=" + ..... .list();
}
我不知道如何建立正确的查询。枚举我存储在我的数据库像tinyint。
这是一个模型。
@Column(name = "type")
@Enumerated(EnumType.ORDINAL)
private ShopType type;
结果应该取决于接收findByType方法Param类型,你编辑的几分钟前刚刚硬编码VANS型 – user3127896 2014-09-29 19:26:48
:) – 2014-09-29 19:28:38
看起来更好,谢谢=) – user3127896 2014-09-29 19:34:46