Browse Source

注解优化

master
nili 3 years ago
parent
commit
407636a8a7
  1. 4
      luigi-service/pom.xml
  2. 5
      luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/PoemService.java
  3. 55
      luigi-service/src/main/java/com/bzgame/server/luigi/service/bo/response/PoemBo.java

4
luigi-service/pom.xml

@ -57,6 +57,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
</dependencies>

5
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);

55
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<Note> 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<List<Note>>() {
}.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<Note> getNoteList() {
if (noteList == null && StringUtils.hasText(getNote())) {
Gson g = new Gson();
try {
noteList = g.fromJson(getNote(), new TypeToken<List<Note>>() {
}.getType());
} catch (Exception ignored) {
}
}
return noteList;
}
public void setNoteList(List<Note> noteList) {
this.noteList = noteList;
}
}

Loading…
Cancel
Save