数据库中存的数字怎么自动转换成中文呢?
这里需要用到注解@DicTrans,看一眼代码,关于省、市、区
@DicTrans(RedisKeyName = RedisHashKeyConst.CITY_KEY_NAME, targetFieldName = "provinceStr")
@ApiModelProperty(value = "省")
@TableField("province_id")
private Long provinceId;
@DicTrans(RedisKeyName = RedisHashKeyConst.CITY_KEY_NAME, targetFieldName = "cityIdStr")
@ApiModelProperty(value = "市")
@TableField("city_id")
private Long cityId;
@DicTrans(RedisKeyName = RedisHashKeyConst.CITY_KEY_NAME, targetFieldName = "areaIdStr")
@ApiModelProperty(value = "区")
@TableField("area_id")
private Long areaId;
@ApiModelProperty(value = "省")
@TableField("province_id")
private String provinceStr;
@ApiModelProperty(value = "市")
@TableField("city_id")
private String cityIdStr;
@ApiModelProperty(value = "区")
@TableField("area_id")
private String areaIdStr;
来看看这里的RedisHashKeyConst(数据存在hash表里面):
//省市区字典
public final static String CITY = "city";
public final static String CITY_NAME_KEY = RedisConstant.dic_project + CITY + RedisConstant.NAME_KEY;
public final static String CITY_KEY_NAME = RedisConstant.dic_project + CITY + RedisConstant.KEY_NAME;
这里是Redis对应的显示视图:
这时候用swagger查询:
{
"cityId": "444"
}返回:
{
"cityId": 444,
"cityIdStr": "河北唐山海港经济开发区",}
数据库表里也存相同的444哦!