我有一个带有rest服务的Spring Web MVC应用程序,我尝试使用Springfox for automated docs。
我用
io.springfox:springfox-swagger2:2.5.0
io.springfox:springfox-swagger-ui:2.5.0
org.webjars:swagger-ui:2.1.4
我的swaggerconfig:
@Configuration
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {
@Bean
public Docket api() {
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build().apiInfo(apiInfo());
return docket;
}
}
@Configuration
@EnableWebMvc
@Profile("dev")
public class SwaggerWebMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
@Api
@RestController
@RequestMapping(RegistrationRestController.ROOT_PATH)
public class RegistrationRestController {
private final static Logger log = LogManager.getLogger(RegistrationRestController.class);
public static final String ROOT_PATH = "/rest/registration";
private final ResponseUtil responseUtil;
private final UserService userService;
@Autowired
public RegistrationRestController(ResponseUtil responseUtil, UserService userService) {
log.debug("Instantiate RegistrationRestController bean");
this.responseUtil = Objects.requireNonNull(responseUtil);
this.userService = Objects.requireNonNull(userService);
}
@RequestMapping(value = {""}, method = RequestMethod.POST)
@ApiResponses({
@ApiResponse(code = 200, message = "Create new user and authorize them. Returns access token", response = AccessTokenDTO.class)
})
@ApiOperation(value = "Create new user", response = AccessTokenDTO.class)
public ResponseDTO newUserRegistration(@Valid @ApiParam(required = true) RegistrationDTO registrationDTO) {
log.debug("POST {} with registrationDTO='{}'", ROOT_PATH, registrationDTO.toString());
AccessTokenDTO accessToken = userService.createUserAndAuthorize(registrationDTO);
return responseUtil.wrapResult(accessToken);
}
}
@ApiModel
public class RegistrationDTO {
@NotNull(message = "registrationDTO.phone.notNull.fail")
@Pattern(regexp = "[0-9]{10}", message = "registrationDTO.phone.pattern.fail")
private String phone;
@NotNull(message = "registrationDTO.email.notNull.fail")
@Email(message = "registrationDTO.email.pattern.fail")
private String email;
@NotNull(message = "registrationDTO.lastName.notNull.fail")
@Size(min = 1, message = "registrationDTO.lastName.size.fail")
private String lastName;
@NotNull(message = "registrationDTO.firstName.notNull.fail")
@Size(min = 1, message = "registrationDTO.firstName.size.fail")
private String firstName;
@NotNull(message = "registrationDTO.password.notNull.fail")
@Size(min = 6, message = "registrationDTO.password.size.fail")
private String password;
@NotNull(message = "registrationDTO.passwordConfirmation.notNull.fail")
@Size(min = 6, message = "registrationDTO.passwordConfirmation.size.fail")
private String passwordConfirmation;
@AssertTrue(message = "registrationDTO.isPasswordMatch.fail")
public boolean isPasswordMatch() {
return Objects.equals(password, passwordConfirmation);
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPasswordConfirmation() {
return passwordConfirmation;
}
public void setPasswordConfirmation(String passwordConfirmation) {
this.passwordConfirmation = passwordConfirmation;
}
@Override
public String toString() {
return "RegistrationDTO{" +
"phone='" + phone + '\'' +
", email='" + email + '\'' +
", lastName='" + lastName + '\'' +
", firstName='" + firstName + '\'' +
'}';
}
}
需要在方法参数之前指定@RequestBody
请帮助解决此错误... 因为我在该对象上使用了bigdecimal类型,而没有添加一个操作@字段(type=FieldType.Double) 有没有办法配置默认的FieldType。大十进制加倍?或者我们需要在每个大十进制中添加字段注释
问题内容: 我需要将网址存储在MySQL表中。定义将包含长度不确定的URL的字段的最佳实践是什么? 问题答案: 流行的Web浏览器中最小的公分母最大URL长度: 2,083 (Internet Explorer) http://dev.mysql.com/doc/refman/5.0/en/char.html VARCHAR列中的值是可变长度的字符串。 在MySQL 5.0.3之前,长度可以指定为
在Kotlin中,您可以创建: 然后可以使用它解析JSON,例如“{n:10}”。在这种情况下,您将有一个对象,从、或接收,它包含以下值:。 在Kotlin+GSON-How to get a emptyList when null for data类中,您可以看到另一个示例。 当您以后尝试使用时,您将在这里得到一个异常::“Kotlin.TypeCastException:null不能被强制转换
是否可以重载一个字段类型成为另一个字段类型? 如果是,是否可以提供一些例子?
我是python数据类的新手,想知道是否有一种聪明的方法为python数据类中的字段定义约束。 假设我们有一个数据类“SomeConfiguration”,它有3个字段(field1、field2、field3),这些字段都是浮点。我所处的环境中经常创建配置对象,并且字段是随机分配的,我希望确保字段的某些约束始终得到满足。例如,以下约束:2*field1>(-1)*field3
这是MongoDB的后续问题:类java.lang.Double不能转换为类java.lang.Long 问题可能是任何指示的字段实际上都存储为Double而不是Long。 是否有一种方法可以强制MongoDB中某些字段的数据类型? 如果数据类型不匹配,我希望插入文档失败。