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); + } + +}