Commit 710bdbd7a5f990eacc6719acdf5e9e703eec4a99
1 parent
76e5d2ea
1.
Showing
2 changed files
with
33 additions
and
0 deletions
src/main/java/com/bsth/controller/realcontrol/AdminUtilsController.java
| 1 | package com.bsth.controller.realcontrol; | 1 | package com.bsth.controller.realcontrol; |
| 2 | 2 | ||
| 3 | +import java.lang.reflect.Field; | ||
| 4 | +import java.lang.reflect.Modifier; | ||
| 3 | import java.text.SimpleDateFormat; | 5 | import java.text.SimpleDateFormat; |
| 4 | import java.util.*; | 6 | import java.util.*; |
| 5 | 7 | ||
| 8 | +import com.bsth.service.schedule.utils.SpringUtils; | ||
| 9 | +import com.fasterxml.jackson.core.JsonProcessingException; | ||
| 10 | +import com.fasterxml.jackson.databind.MapperFeature; | ||
| 11 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 12 | +import com.fasterxml.jackson.databind.SerializationFeature; | ||
| 6 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 7 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 8 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -228,4 +235,27 @@ public class AdminUtilsController { | @@ -228,4 +235,27 @@ public class AdminUtilsController { | ||
| 228 | 235 | ||
| 229 | return rs; | 236 | return rs; |
| 230 | } | 237 | } |
| 238 | + | ||
| 239 | + @RequestMapping("/exportInstance") | ||
| 240 | + public String exportInstance(@RequestParam String classType) { | ||
| 241 | + Map<String, Object> result = new HashMap<>(); | ||
| 242 | + try { | ||
| 243 | + ObjectMapper mapper = new ObjectMapper(); | ||
| 244 | + mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); | ||
| 245 | + Class cls = Class.forName(classType); | ||
| 246 | + Field[] fields = cls.getDeclaredFields(); | ||
| 247 | + for (Field field : fields) { | ||
| 248 | + if (Modifier.isStatic(field.getModifiers()) && field.getName().indexOf("log") == -1) { | ||
| 249 | + field.setAccessible(true); | ||
| 250 | + result.put(field.getName(), field.get(cls)); | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + result.put("_bean", SpringUtils.getBean(Class.forName(classType))); | ||
| 254 | + return mapper.writeValueAsString(result); | ||
| 255 | + } catch (ClassNotFoundException | JsonProcessingException | IllegalAccessException e) { | ||
| 256 | + e.printStackTrace(); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + return "error"; | ||
| 260 | + } | ||
| 231 | } | 261 | } |
| 232 | \ No newline at end of file | 262 | \ No newline at end of file |
src/main/java/com/bsth/entity/schedule/BEntity.java
| 1 | package com.bsth.entity.schedule; | 1 | package com.bsth.entity.schedule; |
| 2 | 2 | ||
| 3 | import com.bsth.entity.sys.SysUser; | 3 | import com.bsth.entity.sys.SysUser; |
| 4 | +import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| 4 | 5 | ||
| 5 | import javax.persistence.*; | 6 | import javax.persistence.*; |
| 6 | import java.util.Date; | 7 | import java.util.Date; |
| @@ -13,9 +14,11 @@ public class BEntity { | @@ -13,9 +14,11 @@ public class BEntity { | ||
| 13 | 14 | ||
| 14 | /** 创建人 */ | 15 | /** 创建人 */ |
| 15 | @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH) | 16 | @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH) |
| 17 | + @JsonIgnore | ||
| 16 | private SysUser createBy; | 18 | private SysUser createBy; |
| 17 | /** 修改人 */ | 19 | /** 修改人 */ |
| 18 | @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH) | 20 | @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH) |
| 21 | + @JsonIgnore | ||
| 19 | private SysUser updateBy; | 22 | private SysUser updateBy; |
| 20 | 23 | ||
| 21 | /** 创建日期 */ | 24 | /** 创建日期 */ |