您的位置:首页 > 其它

关于项目中数据字典的使用(仅供自己记录)

2017-12-13 10:38 435 查看
在字典类中:
public enum CategoryCode {
xx_TYPE("xx类型");// 摄像机类型 1:类型1 2:类型2

/**
* 创建一个新的实例 CategoryCode.
*
* @param label
*/

private CategoryCode(String label) {
this.label = label;
}

public String label;

public String getLable() {
return label;
}
}

之后来到controller层:

@RequestMapping(value = "carmarType", method = RequestMethod.GET)
public void carmarType(HttpServletRequest request,
HttpServletResponse response, Model model) {
JsonResult result = new JsonResult();
DictionaryExample example = new DictionaryExample();
example.createCriteria().andCategoryCodeEqualTo(
CategoryCode.CARMAR_TYPE.name());
List<Dictionary> list = dictionaryService.selectByExample(example);
if (list != null && list.size() > 0) {
result.setSuccess(true);
result.setData(list);
}
writeJson(response, JSON.toJSON(result));
}
DictionaryExample是字典的一个实现类的方法,里面包含许多方法这里就不贴代码了。
最后在数据库手动添加一些数据进行测试。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: