实现删除和更新数据接口
This commit is contained in:
@@ -32,6 +32,7 @@ public class AddBookController {
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
*
|
||||
* @param title
|
||||
* @param author
|
||||
* @param wordCount
|
||||
@@ -43,7 +44,7 @@ public class AddBookController {
|
||||
@RequestParam(name = "author") String author,
|
||||
@RequestParam(name = "word_count") int wordCount,
|
||||
@RequestParam(name = "publish_date")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDate) {
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd") Date publishDate) {
|
||||
String type = "novel";
|
||||
|
||||
// 格式化日期
|
||||
@@ -53,20 +54,20 @@ public class AddBookController {
|
||||
try {
|
||||
// 用自带的构造文档
|
||||
XContentBuilder content = XContentFactory.jsonBuilder().startObject()
|
||||
.field("title",title)
|
||||
.field("author",author)
|
||||
.field("word_count",wordCount)
|
||||
.field("publish_date",dateStr)
|
||||
.field("type",type)
|
||||
.field("title", title)
|
||||
.field("author", author)
|
||||
.field("word_count", wordCount)
|
||||
.field("publish_date", dateStr)
|
||||
.field("type", type)
|
||||
.endObject();
|
||||
|
||||
IndexResponse response = this.client.prepareIndex("book",type).setSource(content).get();
|
||||
IndexResponse response = this.client.prepareIndex("book", type).setSource(content).get();
|
||||
|
||||
// 返回结果带上新增的ID
|
||||
return new ResponseEntity(response.getId(), HttpStatus.OK);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("【title】"+title+"【author】"+author+"【wordCount】"+wordCount+"【publishDate】"+publishDate);
|
||||
log.error("【title】" + title + "【author】" + author + "【wordCount】" + wordCount + "【publishDate】" + publishDate);
|
||||
return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user