diff --git a/luigi-service/pom.xml b/luigi-service/pom.xml index 4b93cd3..b47c033 100644 --- a/luigi-service/pom.xml +++ b/luigi-service/pom.xml @@ -57,6 +57,10 @@ com.fasterxml.jackson.core jackson-annotations + + com.google.code.gson + gson + diff --git a/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java b/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java index 3518f35..af273d0 100644 --- a/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java +++ b/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java @@ -10,6 +10,7 @@ import com.bzgame.server.luigi.dao.mapper.manual.ManualMapper; import com.bzgame.server.luigi.service.bo.request.PoemQuery; import com.bzgame.server.luigi.service.bo.response.CommonList; import com.bzgame.server.luigi.service.bo.response.PoemBo; +import com.google.gson.Gson; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -59,6 +60,10 @@ public class PoemService { @Transactional public Integer save(PoemBo poemBo) { Poem p = new Poem(); + if (!CollectionUtils.isEmpty(poemBo.getNoteList())) { + Gson g = new Gson(); + poemBo.setNote(g.toJson(poemBo.getNoteList())); + } if (poemBo.getId() == null) { manualMapper.incrAuthorPoemCnt(poemBo.getAuthorId()); BeanUtils.copyProperties(poemBo, p); diff --git a/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/response/PoemBo.java b/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/response/PoemBo.java index 148979f..5cdc883 100644 --- a/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/response/PoemBo.java +++ b/luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/response/PoemBo.java @@ -1,19 +1,56 @@ package com.bzgame.server.luigi.service.bo.response; import com.bzgame.server.luigi.dao.domain.Poem; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.springframework.beans.BeanUtils; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.List; /** * @author nidaren */ public class PoemBo extends Poem { private String authorName; + private List noteList; public PoemBo() { } public PoemBo(Poem p) { BeanUtils.copyProperties(p, this); + if (!StringUtils.hasText(p.getNote())) { + return; + } + Gson g = new Gson(); + try { + noteList = g.fromJson(p.getNote(), new TypeToken>() { + }.getType()); + } catch (Exception ignored) { + } + } + + static class Note { + private String citation; + private String annotation; + + public String getCitation() { + return citation; + } + + public void setCitation(String citation) { + this.citation = citation; + } + + public String getAnnotation() { + return annotation; + } + + public void setAnnotation(String annotation) { + this.annotation = annotation; + } } public String getAuthorName() { @@ -23,4 +60,22 @@ public class PoemBo extends Poem { public void setAuthorName(String authorName) { this.authorName = authorName; } + + public List getNoteList() { + if (noteList == null && StringUtils.hasText(getNote())) { + Gson g = new Gson(); + try { + noteList = g.fromJson(getNote(), new TypeToken>() { + }.getType()); + } catch (Exception ignored) { + + } + + } + return noteList; + } + + public void setNoteList(List noteList) { + this.noteList = noteList; + } }