更改了两个响应包装类的包路径,让swagger变得可用了,修复了ProjectController中不能正常限制条件的Bug
parent
fc99117637
commit
e70e0c5f5a
|
@ -1,5 +1,6 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
|
@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* @author 佘语殊
|
||||
* @since 2022/6/27 11:24
|
||||
*/
|
||||
@Api(tags = "hello")
|
||||
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
|
||||
@RestController
|
||||
public class ProjectManagement {
|
||||
|
|
|
@ -2,7 +2,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.advice;
|
|||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
|
|
@ -4,11 +4,15 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Jackson序列化配置,主要配置了{@link LocalDateTime} {@link LocalDate} {@link LocalTime}转为秒级时间戳的序列化
|
||||
|
@ -77,4 +81,20 @@ public class SerializeConfig {
|
|||
return om;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"Convert2Diamond", "NullableProblems", "rawtypes"})
|
||||
@Bean
|
||||
public Converter<String, Map> MapConverter() {
|
||||
return new Converter<String, Map>() {
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public Map convert(String source) {
|
||||
return objectMapper.readValue(source, Map.class);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.oas.annotations.EnableOpenApi;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
|
@ -17,7 +18,8 @@ import java.util.ArrayList;
|
|||
* @since 2022/6/27 11:24
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2 //开启Swagger2
|
||||
//@EnableSwagger2 //开启Swagger2
|
||||
@EnableOpenApi
|
||||
public class SwaggerConfig {
|
||||
|
||||
//配置 Swagger的Docket的Bean实例
|
||||
|
|
|
@ -28,9 +28,8 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
registry.addInterceptor(getCorsInterceptor()).addPathPatterns("/**");
|
||||
registry.addInterceptor(getTokenInterceptor())
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/staff/login")
|
||||
.excludePathPatterns("/hello")
|
||||
.excludePathPatterns("/error")
|
||||
.excludePathPatterns("/swagger-ui/**");
|
||||
.excludePathPatterns("/hello", "/error") //测试
|
||||
.excludePathPatterns("/staff/login") //登录
|
||||
.excludePathPatterns("/swagger-resources/**", "/swagger-ui/**", "/v3/**", "/v2/**"); //swagger
|
||||
}
|
||||
}
|
|
@ -3,9 +3,12 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
|||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Project;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ResultProject;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -24,18 +27,24 @@ public class ProjectController {
|
|||
@Autowired
|
||||
private IProjectService projectService;
|
||||
|
||||
@ApiOperation("根据Token获取该员工的ProjectList")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "paramMap", value = "参数列表见Project实体类,时间可以用xxxxStart与xxxxEnd来确定区间"
|
||||
, required = true)
|
||||
})
|
||||
@SneakyThrows
|
||||
@GetMapping
|
||||
public ResponseList<ResultProject> getProjectListOfStaff(
|
||||
@RequestHeader("Token") String token,
|
||||
@RequestParam("pageCurrent") Integer pageCurrent,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
Map<String, Object> paramMap
|
||||
@RequestParam("pageCurrent") Integer pageCurrent,
|
||||
@RequestParam("paramMap") Map<String, Object> paramMap
|
||||
) {
|
||||
Page<ResultProject> page = projectService.getOnePageProject(token, pageCurrent, pageSize, paramMap);
|
||||
return ResponseList.ofSuccess("成功返回列表", page);
|
||||
}
|
||||
|
||||
@ApiOperation("根据Token获取该员工的Project数")
|
||||
@SneakyThrows
|
||||
@GetMapping("/total")
|
||||
public ResponseMap getProjectNumOfStaff(@RequestHeader("Token") String token) {
|
||||
|
@ -44,6 +53,10 @@ public class ProjectController {
|
|||
return ResponseMap.ofSuccess("获得参与项目总数", res);
|
||||
}
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "map", value = "用于读取整个RequestBody,实际传参时无意义,请忽略"),
|
||||
@ApiImplicitParam(paramType = "body", dataTypeClass = Integer.class, name = "projectId", required = true)
|
||||
})
|
||||
@SneakyThrows
|
||||
@PostMapping("/complete")
|
||||
public ResponseMap completeProject(@RequestHeader("Token") String token, @RequestBody Map<String, Object> map) {
|
||||
|
|
|
@ -2,7 +2,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
|||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.ProjectType;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IProjectTypeService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseList;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
|
|
@ -3,7 +3,9 @@ package cn.edu.hfut.rmdjzz.projectmanagement.controller;
|
|||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -18,6 +20,9 @@ public class StaffController {
|
|||
@Autowired
|
||||
private IStaffService staffService;
|
||||
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "staff", value = "只需要传入staffUsername和staffPassword两个属性即可,staffPassword需要md5加密后传输")
|
||||
})
|
||||
@SneakyThrows
|
||||
@PostMapping("/login")
|
||||
public ResponseMap login(@RequestBody Staff staff) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -24,6 +23,7 @@ public class TokenInterceptor implements HandlerInterceptor {
|
|||
@Autowired
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
|
||||
//FIXME: 最终上线时要把这里的输出删掉
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object object) throws TokenException {
|
||||
System.out.println(httpServletRequest.getRequestURL() + " " + httpServletRequest.getMethod());
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.edu.hfut.rmdjzz.projectmanagement.service;
|
|||
import cn.edu.hfut.rmdjzz.projectmanagement.entity.Staff;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.BadRequestException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -82,6 +82,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|||
throw new BadRequestException("参数错误");
|
||||
}
|
||||
|
||||
//FIXME: 改为特定Exception处理
|
||||
try {
|
||||
if (baseMapper.insert(project) == 1) {
|
||||
return projectGroupService.addCreator(project.getProjectId(), TokenUtils.getStaffId(token));
|
||||
|
|
|
@ -6,7 +6,7 @@ import cn.edu.hfut.rmdjzz.projectmanagement.exception.TokenException;
|
|||
import cn.edu.hfut.rmdjzz.projectmanagement.mapper.StaffMapper;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.service.IStaffService;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.TokenUtils;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.response.ResponseMap;
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.http.ResponseMap;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.utils.response;
|
||||
package cn.edu.hfut.rmdjzz.projectmanagement.utils.http;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.AccessLevel;
|
|
@ -1,4 +1,4 @@
|
|||
package cn.edu.hfut.rmdjzz.projectmanagement.utils.response;
|
||||
package cn.edu.hfut.rmdjzz.projectmanagement.utils.http;
|
||||
|
||||
import cn.edu.hfut.rmdjzz.projectmanagement.utils.BeanUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@ -36,7 +36,7 @@ public class MybatisPlusTests {
|
|||
|
||||
@Test
|
||||
public void test() {
|
||||
staffService.page(new Page<Staff>(2, 1));
|
||||
staffService.page(new Page<>(2, 1));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
|
@ -48,6 +48,7 @@ public class MybatisPlusTests {
|
|||
map.put("etimeEnd", LocalDate.now());*/
|
||||
map.put("null", null);
|
||||
map.put("deleted", true);
|
||||
map.put("completed", true);
|
||||
QueryWrapper<String> wrapper = WrapperUtils.allEqAndTimeIntervalQueryWrapper(map, true, true, true);
|
||||
System.out.println(wrapper.getCustomSqlSegment());
|
||||
System.out.println(objectMapper.writeValueAsString(wrapper.getParamNameValuePairs()));
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author 佘语殊
|
||||
|
|
Loading…
Reference in New Issue