From bd76f4462d818a5b48c3dc8f3c5f55b88a3e2573 Mon Sep 17 00:00:00 2001 From: insanity Date: Wed, 28 Jun 2017 14:49:32 +0900 Subject: [PATCH] . --- .../overflow/module/commons/OFService.java | 21 +++++++++++++++ .../module/target/service/TargetService.java | 27 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/com/loafle/overflow/module/commons/OFService.java create mode 100644 src/main/java/com/loafle/overflow/module/target/service/TargetService.java diff --git a/src/main/java/com/loafle/overflow/module/commons/OFService.java b/src/main/java/com/loafle/overflow/module/commons/OFService.java new file mode 100644 index 0000000..d28c451 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/commons/OFService.java @@ -0,0 +1,21 @@ +package com.loafle.overflow.module.commons; + +import org.codehaus.jackson.map.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Created by insanity on 17. 6. 28. + */ +public class OFService { + + @Autowired + private ObjectMapper mapper; + + public String toString(Object o) { + try { + return mapper.writeValueAsString(o); + }catch(Exception e) { + return e.getMessage(); + } + } +} diff --git a/src/main/java/com/loafle/overflow/module/target/service/TargetService.java b/src/main/java/com/loafle/overflow/module/target/service/TargetService.java new file mode 100644 index 0000000..c8e809a --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/target/service/TargetService.java @@ -0,0 +1,27 @@ +package com.loafle.overflow.module.target.service; + + +import com.loafle.overflow.module.commons.OFService; +import com.loafle.overflow.module.target.dao.TargetDAO; +import com.loafle.overflow.module.target.model.Target; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Created by insanity on 17. 6. 28. + */ +public class TargetService extends OFService { + + @Autowired + private TargetDAO targetDAO; + + public String regist(Target target) { + Target t = this.targetDAO.save(target); + return toString(t); + } + + public String read(String id) { + Target t = this.targetDAO.findOne(Long.valueOf(id)); + return toString(t); + } + +}