新增文献接口开发
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -75,3 +75,7 @@ runConfigurations/
|
||||
# 测试报告
|
||||
surefire-reports/
|
||||
failsafe-reports/
|
||||
|
||||
# 忽略所有媒体文件夹内容,不上传到Git
|
||||
/media/img/*
|
||||
/media/video/*
|
||||
1
pom.xml
1
pom.xml
@@ -60,6 +60,7 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Knife4j -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
|
||||
40
src/main/java/com/genepioneer/config/OpenApiConfig.java
Normal file
40
src/main/java/com/genepioneer/config/OpenApiConfig.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.genepioneer.config;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Knife4j + OpenAPI 3 文档主信息配置(无externalDocs)
|
||||
*/
|
||||
@Configuration
|
||||
public class OpenApiConfig {
|
||||
|
||||
@Bean
|
||||
public OpenAPI myOpenAPI() {
|
||||
return new OpenAPI()
|
||||
.info(new Info()
|
||||
|
||||
.title("genepioneer接口文档")
|
||||
.description("OpenAPI 3接口文档")
|
||||
.version("v1.0.0")
|
||||
.license(new License()
|
||||
.name("Apache 2.0")
|
||||
.url("https://www.apache.org/licenses/LICENSE-2.0")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// 分组1:文献管理接口
|
||||
@Bean
|
||||
public GroupedOpenApi literatureApi() {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("文献管理接口") // 分组名称
|
||||
.packagesToScan("com.genepioneer.controller") // 匹配的接口路径
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,7 @@ import com.genepioneer.service.LiteratureService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/literature")
|
||||
@@ -19,7 +16,7 @@ public class LiteratureController {
|
||||
@Autowired
|
||||
private LiteratureService literatureService;
|
||||
|
||||
// 接收前端POST请求,保存文献数据
|
||||
// 新增文献数据
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增文献")
|
||||
public Result<String> addLiterature(@RequestBody LiteratureDTO literatureDTO) {
|
||||
@@ -33,4 +30,17 @@ public class LiteratureController {
|
||||
return Result.error("新增文献失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 新增:删除文献接口
|
||||
@DeleteMapping("/delete/{id}") // 通过路径变量接收文献ID
|
||||
@Operation(summary = "删除文献")
|
||||
public Result<String> deleteLiterature(@PathVariable Long id) { // @PathVariable绑定路径中的id参数
|
||||
try {
|
||||
literatureService.deleteLiterature(id);
|
||||
return Result.success("删除文献成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("删除文献失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
package com.genepioneer.mapper;
|
||||
|
||||
import com.genepioneer.entity.LiteratureInfo;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface LiteratureMapper {
|
||||
|
||||
// 插入文献数据(字段对应entity的属性)
|
||||
// 插入文献数据
|
||||
@Insert("INSERT INTO literature_info(year, article_title, journal_name, impact_factor, sample_source, literature_type,literature_url) " +
|
||||
"VALUES(#{year}, #{articleTitle}, #{journalName}, #{impactFactor}, #{sampleSource}, #{literatureType},#{literatureUrl})")
|
||||
int insertLiterature(LiteratureInfo literatureInfo);
|
||||
|
||||
|
||||
// 根据文献ID删除数据
|
||||
@Delete("DELETE FROM literature_info WHERE id = #{id}")
|
||||
void deleteLiteratureById(Long id);
|
||||
}
|
||||
@@ -5,4 +5,7 @@ import com.genepioneer.dto.LiteratureDTO;
|
||||
public interface LiteratureService {
|
||||
// 新增文献
|
||||
void addLiterature(LiteratureDTO literatureDTO);
|
||||
|
||||
// 删除文献
|
||||
void deleteLiterature(Long id);
|
||||
}
|
||||
@@ -14,6 +14,11 @@ public class LiteratureServiceImpl implements LiteratureService {
|
||||
@Autowired
|
||||
private LiteratureMapper literatureMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 新增文献
|
||||
* @param literatureDTO
|
||||
*/
|
||||
@Override
|
||||
public void addLiterature(LiteratureDTO literatureDTO) {
|
||||
// 把DTO转成Entity
|
||||
@@ -23,4 +28,13 @@ public class LiteratureServiceImpl implements LiteratureService {
|
||||
// 调用Mapper插入数据库
|
||||
literatureMapper.insertLiterature(literatureInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文献
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void deleteLiterature(Long id) {
|
||||
literatureMapper.deleteLiteratureById(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user