Map 属性以JSON 形式存于数据库

1import java.util.HashMap; 2import java.util.Map; 3 4import javax.persistence.Id; 5import javax.persistence.MappedSuperclass; 6import javax.persistence.Transient; 7 8import org.codehaus.jackson.annotate.JsonIgnore; 9 10 11@MappedSuperclass 12public class MenuDefinition { 13 14 /** 15 * menu's unique id. 16 * <p> 17 * 建议使用包格式 18 * </p> 19 */ 20 String id; 21 22 /** 23 * 菜单显示标签,一个简短的字符串. 24 */ 25 String label; 26 27 /** 28 * 与上一级菜单的关联. 这是一个弱关联的关系。除了参考id以外还能够使用位置表达式。 29 * 30 */ 31 String parentId; 32 33 /** 34 * 同级菜单排序,二维表格没有顺序值,所以需要记录,默认值应该是0. 35 */ 36 Integer seq = 0; 37 38 /** 39 * 描述字段,详细描述label。. 40 * 41 */ 42 String tooltip; 43 44 /** 45 * 菜单功能键,一个标准的URI表达式。. 46 */ 47 String URI; 48 49 /** 50 * 菜单图标地址,URL表达式。. 51 */ 52 String icon; 53 54 /** 55 * 类别,用来对菜单子类做区分。. 56 */ 57 String type; 58 59 /** 60 * 上下文帮助id.一个字符串. 61 */ 62 String helpContextId; 63 64 /** 65 * Available,一个条件表达式,用来计算菜单在当前的上下文中是否能够显示。. 66 */ 67 String available; 68 69 /** 70 * 助记符,单个字母的快捷键提示。. 71 */ 72 String mnemonic; 73 74 /** 75 * 可扩展的字段. 76 * 77 */ 78 Map<String, Object> extra = new HashMap<String, Object>(5); 79 80 public MenuDefinition() { 81 82 } 83 84 /** 85 * Gets the available,一个条件表达式,用来计算菜单在当前的上下文中是否能够显示。. 86 * 87 * @return the available,一个条件表达式,用来计算菜单在当前的上下文中是否能够显示。 88 */ 89 public String getAvailable() { 90 return available; 91 } 92 93 /** 94 * Sets the available,一个条件表达式,用来计算菜单在当前的上下文中是否能够显示。. 95 * 96 * @param available 97 * the new available,一个条件表达式,用来计算菜单在当前的上下文中是否能够显示。 98 */ 99 public void setAvailable(String available) { 100 this.available = available; 101 } 102 103 /** 104 * Gets the menu's unique id. 105 * 106 * @return the menu's unique id 107 */ 108 @Id 109 public String getId() { 110 return id; 111 } 112 113 /** 114 * Sets the menu's unique id. 115 * 116 * @param id 117 * the new menu's unique id 118 */ 119 public void setId(String id) { 120 this.id = id; 121 } 122 123 /** 124 * Gets the 菜单显示标签,一个简短的字符串. 125 * 126 * @return the 菜单显示标签,一个简短的字符串 127 */ 128 public String getLabel() { 129 return label; 130 } 131 132 /** 133 * Sets the 菜单显示标签,一个简短的字符串. 134 * 135 * @param label 136 * the new 菜单显示标签,一个简短的字符串 137 */ 138 public void setLabel(String label) { 139 this.label = label; 140 } 141 142 /** 143 * Gets the 与上一级菜单的关联. 144 * 145 * @return the 与上一级菜单的关联 146 */ 147 public String getParentId() { 148 return parentId; 149 } 150 151 /** 152 * Sets the 与上一级菜单的关联. 153 * 154 * @param parentId 155 * the new 与上一级菜单的关联 156 */ 157 public void setParentId(String parentId) { 158 this.parentId = parentId; 159 } 160 161 /** 162 * Gets the 同级菜单排序,二维表格没有顺序值,所以需要记录。. 163 * 164 * @return the 同级菜单排序,二维表格没有顺序值,所以需要记录。 165 */ 166 public int getSeq() { 167 return seq; 168 } 169 170 /** 171 * Sets the 同级菜单排序,二维表格没有顺序值,所以需要记录。. 172 * 173 * @param seq 174 * the new 同级菜单排序,二维表格没有顺序值,所以需要记录。 175 */ 176 public void setSeq(Integer seq) { 177 if (seq != null) { 178 this.seq = seq; 179 } 180 } 181 182 /** 183 * Sets the 同级菜单排序,二维表格没有顺序值,所以需要记录。. 184 * 185 * @param seq 186 * the new 同级菜单排序,二维表格没有顺序值,所以需要记录。 187 */ 188 @JsonIgnore 189 public void setSeq(int seq) { 190 this.seq = seq; 191 } 192 193 /** 194 * Gets the 描述字段,详细描述label。. 195 * 196 * @return the 描述字段,详细描述label。 197 */ 198 public String getTooltip() { 199 return tooltip; 200 } 201 202 /** 203 * Sets the 描述字段,详细描述label。. 204 * 205 * @param tooltip 206 * the new 描述字段,详细描述label。 207 */ 208 public void setTooltip(String tooltip) { 209 this.tooltip = tooltip; 210 } 211 212 /** 213 * Gets the 菜单功能键,一个标准的URI表达式。. 214 * 215 * @return the 菜单功能键,一个标准的URI表达式。 216 */ 217 public String getUri() { 218 return URI; 219 } 220 221 /** 222 * Sets the 菜单功能键,一个标准的URI表达式。. 223 * 224 * @param getURI 225 * the new 菜单功能键,一个标准的URI表达式。 226 */ 227 public void setUri(String getURI) { 228 this.URI = getURI; 229 } 230 231 /** 232 * Gets the 菜单图标地址,URL表达式。. 233 * 234 * @return the 菜单图标地址,URL表达式。 235 */ 236 public String getIcon() { 237 return icon; 238 } 239 240 /** 241 * Sets the 菜单图标地址,URL表达式。. 242 * 243 * @param icon 244 * the new 菜单图标地址,URL表达式。 245 */ 246 public void setIcon(String icon) { 247 this.icon = icon; 248 } 249 250 /** 251 * Gets the 类别,用来对菜单子类做区分。. 252 * 253 * @return the 类别,用来对菜单子类做区分。 254 */ 255 public String getType() { 256 return type; 257 } 258 259 /** 260 * Sets the 类别,用来对菜单子类做区分。. 261 * 262 * @param type 263 * the new 类别,用来对菜单子类做区分。 264 */ 265 public void setType(String type) { 266 this.type = type; 267 } 268 269 /** 270 * Gets the 上下文帮助id. 271 * 272 * @return the 上下文帮助id 273 */ 274 public String getHelpContextId() { 275 return helpContextId; 276 } 277 278 /** 279 * Sets the 上下文帮助id. 280 * 281 * @param helpContextId 282 * the new 上下文帮助id 283 */ 284 public void setHelpContextId(String helpContextId) { 285 this.helpContextId = helpContextId; 286 } 287 288 /** 289 * Gets the 可扩展的字段. 290 * 291 * @return the 可扩展的字段 292 */ 293 @Transient 294 public Map<String, Object> getExtra() { 295 return extra; 296 } 297 298 /** 299 * Sets the 可扩展的字段. 300 * 301 * @param extra 302 * the new 可扩展的字段 303 */ 304 public void setExtra(Map<String, Object> extra) { 305 this.extra = extra; 306 } 307 308 /** 309 * Gets the 助记符,单个字母的快捷键提示。. 310 * 311 * @return the 助记符,单个字母的快捷键提示。 312 */ 313 public String getMnemonic() { 314 return mnemonic; 315 } 316 317 /** 318 * Sets the 助记符,单个字母的快捷键提示。. 319 * 320 * @param mnemonic 321 * the new 助记符,单个字母的快捷键提示。 322 */ 323 public void setMnemonic(String mnemonic) { 324 this.mnemonic = mnemonic; 325 } 326} 327 328package com.lee.mvc.core.menu.jpa; 329 330import java.io.IOException; 331import java.util.Map; 332 333import javax.persistence.AttributeOverride; 334import javax.persistence.Column; 335import javax.persistence.Entity; 336import javax.persistence.Table; 337 338import org.codehaus.jackson.JsonGenerationException; 339import org.codehaus.jackson.JsonParseException; 340import org.codehaus.jackson.map.JsonMappingException; 341import org.codehaus.jackson.map.ObjectMapper; 342 343import com.lee.mvc.core.menu.MenuDefinition; 344 345@Entity(name="menuDefinitionJpa") 346@Table(name = "jmoco_ui_menu") 347@AttributeOverride(name = "extra", column = @Column(name = "extra")) 348public class MenuDefinitionJpa extends MenuDefinition { 349 ObjectMapper objectMapper = new ObjectMapper(); 350 351 /** 352 * 返回扩展JSON字段,如果解析异常,就返回“{}353 * 354 * @return 355 */ 356 @Column(name = "extra") 357 public String getExtraJsonString() { 358 if (getExtra().size() > 0) { 359 try { 360 return objectMapper.writeValueAsString(getExtra()); 361 } catch (JsonGenerationException e) { 362 // TODO Auto-generated catch block 363 e.printStackTrace(); 364 } catch (JsonMappingException e) { 365 // TODO Auto-generated catch block 366 e.printStackTrace(); 367 } catch (IOException e) { 368 // TODO Auto-generated catch block 369 e.printStackTrace(); 370 } 371 } else { 372 return "{}"; 373 } 374 return null; 375 } 376 377 /** 378 * 设置扩展的JSNO字符串。 379 * 380 * @param json 381 */ 382 public void setExtraJsonString(String json) { 383 if (json == null || "".equals(json)) { 384 385 } else { 386 try { 387 @SuppressWarnings("unchecked") 388 Map<String, Object> readValue = objectMapper.readValue(json, Map.class); 389 setExtra(readValue); 390 } catch (JsonParseException e) { 391 e.printStackTrace(); 392 } catch (JsonMappingException e) { 393 e.printStackTrace(); 394 } catch (IOException e) { 395 e.printStackTrace(); 396 } finally { 397 } 398 } 399 } 400}
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )