parent
8154807f90
commit
1ffa7c4a75
|
@ -1,9 +1,11 @@
|
||||||
package com.guwan.backend;
|
package com.guwan.backend;
|
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@Slf4j
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@MapperScan("com.guwan.backend.mapper")
|
@MapperScan("com.guwan.backend.mapper")
|
||||||
public class BackendApplication {
|
public class BackendApplication {
|
||||||
|
@ -12,4 +14,10 @@ public class BackendApplication {
|
||||||
SpringApplication.run(BackendApplication.class, args);
|
SpringApplication.run(BackendApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
log.info("大爱仙尊: http://localhost:8084/daxz.html?id=1");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.guwan.backend.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||||
|
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author roc
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class LocalDateTimeConfiguration {
|
||||||
|
|
||||||
|
@Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
|
||||||
|
private String pattern;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
|
||||||
|
return builder -> {
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
|
||||||
|
|
||||||
|
//返回时间数据序列化
|
||||||
|
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(formatter));
|
||||||
|
//接收时间数据反序列化
|
||||||
|
builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(formatter));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,7 @@ public class SecurityConstants {
|
||||||
* 这些路径可以直接访问,不需要认证
|
* 这些路径可以直接访问,不需要认证
|
||||||
*/
|
*/
|
||||||
public static final List<String> WHITE_LIST = List.of(
|
public static final List<String> WHITE_LIST = List.of(
|
||||||
"/common/**", //公共接口
|
"/api/common/**", //公共接口
|
||||||
"/demo/**", // 测试接口
|
"/demo/**", // 测试接口
|
||||||
"/api/products",
|
"/api/products",
|
||||||
"/api/user/register", // 用户注册
|
"/api/user/register", // 用户注册
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class BookController {
|
||||||
private final BookService bookService;
|
private final BookService bookService;
|
||||||
|
|
||||||
@Operation(summary = "添加图书")
|
@Operation(summary = "添加图书")
|
||||||
@PostMapping
|
@PostMapping("/add")
|
||||||
public Result<Book> addBook(@RequestBody Book book) {
|
public Result<Book> addBook(@RequestBody Book book) {
|
||||||
try {
|
try {
|
||||||
return Result.success(bookService.addBook(book));
|
return Result.success(bookService.addBook(book));
|
||||||
|
@ -30,6 +30,22 @@ public class BookController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询图书列表")
|
||||||
|
@GetMapping
|
||||||
|
public Result<IPage<Book>> getBookList(
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||||
|
@RequestParam(required = false) String keyword) {
|
||||||
|
try {
|
||||||
|
return Result.success(bookService.getBookList(pageNum, pageSize, keyword));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("查询图书列表失败", e);
|
||||||
|
return Result.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "更新图书信息")
|
@Operation(summary = "更新图书信息")
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public Result<Book> updateBook(@PathVariable Long id, @RequestBody Book book) {
|
public Result<Book> updateBook(@PathVariable Long id, @RequestBody Book book) {
|
||||||
|
@ -76,19 +92,7 @@ public class BookController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "分页查询图书列表")
|
|
||||||
@GetMapping
|
|
||||||
public Result<IPage<Book>> getBookList(
|
|
||||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
|
||||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
||||||
@RequestParam(required = false) String keyword) {
|
|
||||||
try {
|
|
||||||
return Result.success(bookService.getBookList(pageNum, pageSize, keyword));
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("查询图书列表失败", e);
|
|
||||||
return Result.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "根据分类获取图书")
|
@Operation(summary = "根据分类获取图书")
|
||||||
@GetMapping("/category/{category}")
|
@GetMapping("/category/{category}")
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/common")
|
@RequestMapping("/api/common")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CommonController {
|
public class CommonController {
|
||||||
|
|
||||||
|
@ -122,6 +122,8 @@ public class CommonController {
|
||||||
|
|
||||||
ArrayList<BookContent> bookContents = new ArrayList<>();
|
ArrayList<BookContent> bookContents = new ArrayList<>();
|
||||||
|
|
||||||
|
int sectionId = 1;
|
||||||
|
|
||||||
// 输出卷和节信息
|
// 输出卷和节信息
|
||||||
for (int i = 0; i < volumes.size(); i++) {
|
for (int i = 0; i < volumes.size(); i++) {
|
||||||
// 输出卷的标题
|
// 输出卷的标题
|
||||||
|
@ -153,6 +155,7 @@ public class CommonController {
|
||||||
bookContent.setVolume(volumes.get(i));
|
bookContent.setVolume(volumes.get(i));
|
||||||
bookContent.setSection(section);
|
bookContent.setSection(section);
|
||||||
bookContent.setSectionContent(sectionContent);
|
bookContent.setSectionContent(sectionContent);
|
||||||
|
bookContent.setSectionId(sectionId++);
|
||||||
|
|
||||||
System.out.println("bookContent = " + bookContent);
|
System.out.println("bookContent = " + bookContent);
|
||||||
|
|
||||||
|
@ -174,6 +177,13 @@ public class CommonController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/getBookContent")
|
||||||
|
public Result<String> getBookContent(String bookName, Long id) {
|
||||||
|
BookContent bookContent = bookContentService.getBookContent(bookName, id);
|
||||||
|
return Result.success(bookContent.getSectionContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/getBookCommentByPath")
|
@GetMapping("/getBookCommentByPath")
|
||||||
|
|
|
@ -14,16 +14,14 @@ public class Book {
|
||||||
private String author; // 作者
|
private String author; // 作者
|
||||||
private String publisher; // 出版社
|
private String publisher; // 出版社
|
||||||
private String description; // 描述
|
private String description; // 描述
|
||||||
|
private String bookUrl; // 图书内容url
|
||||||
private String coverUrl; // 封面图片URL
|
private String coverUrl; // 封面图片URL
|
||||||
private String category; // 分类
|
private String category; // 分类
|
||||||
private String tags; // 标签(逗号分隔)
|
private String tags; // 标签(逗号分隔)
|
||||||
private Integer totalPages; // 总页数
|
|
||||||
private String language; // 语言
|
private String language; // 语言
|
||||||
private LocalDateTime publishDate; // 出版日期
|
private LocalDateTime publishDate; // 出版日期
|
||||||
|
|
||||||
@TableField(fill = FieldFill.INSERT)
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
private LocalDateTime updatedTime;
|
private LocalDateTime updatedTime;
|
||||||
}
|
}
|
|
@ -15,4 +15,6 @@ public class BookContent {
|
||||||
private String volume;
|
private String volume;
|
||||||
private String section;
|
private String section;
|
||||||
private String sectionContent;
|
private String sectionContent;
|
||||||
|
private Integer sectionId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.guwan.backend.entity.BookContent;
|
||||||
|
|
||||||
|
|
||||||
public interface BookContentService extends IService<BookContent> {
|
public interface BookContentService extends IService<BookContent> {
|
||||||
|
BookContent getBookContent(String bookName, Long id);
|
||||||
// 添加书籍
|
// 添加书籍
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,12 +1,24 @@
|
||||||
package com.guwan.backend.service.impl;
|
package com.guwan.backend.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.guwan.backend.entity.BookContent;
|
import com.guwan.backend.entity.BookContent;
|
||||||
import com.guwan.backend.mapper.BookContentMapper;
|
import com.guwan.backend.mapper.BookContentMapper;
|
||||||
import com.guwan.backend.service.BookContentService;
|
import com.guwan.backend.service.BookContentService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class BookContentServiceImpl extends ServiceImpl<BookContentMapper, BookContent> implements BookContentService {
|
public class BookContentServiceImpl extends ServiceImpl<BookContentMapper, BookContent> implements BookContentService {
|
||||||
|
|
||||||
|
|
||||||
|
private final BookContentMapper bookContentMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BookContent getBookContent(String bookName, Long id) {
|
||||||
|
return bookContentMapper.selectOne(new LambdaQueryWrapper<BookContent>()
|
||||||
|
.eq(BookContent::getBookName, bookName)
|
||||||
|
.eq(BookContent::getSectionId, id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ CREATE TABLE IF NOT EXISTS `book_content` (
|
||||||
`volume` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
`volume` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
||||||
`section` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
`section` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
|
||||||
`section_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
|
`section_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL,
|
||||||
|
`section_id` int DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`) USING BTREE
|
PRIMARY KEY (`id`) USING BTREE
|
||||||
) ENGINE = InnoDB AUTO_INCREMENT = 2342 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
|
) ENGINE = InnoDB AUTO_INCREMENT = 2342 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue