java - 我想从 MessageResource 即 message.properties 读取我的界面内的文档部分
问题描述
我的项目结构如下
src
- /com/dev/api
APIInterface.java
APIController.java
- /resources
-i18
-messages.properties
我的 API 接口看起来像 APIInterface.java
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.Size;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
@RestController
@Validated
@Tag(name = "Definition Inquiry", description = "The Definition API")
public interface APIInterface {
@Operation(summary = "{summary.api}", description = "Get List of Definitions on dp number search.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successful response", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = DefinitionOne.class)) }),
@ApiResponse(responseCode = "204", description = "No Content", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = String.class)) }),
@ApiResponse(responseCode = "500", description = "Internal Error", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = FailureDefinition.class)) }) })
@GetMapping("/dev/defs")
ResponseEntity<List<DefSummary>> getDefinitions(
@Parameter(description = "Definition Parameter")
@RequestParam("df")
@Valid
@Size(min=7,message="{dp.length.fail.msg}")
String df) throws Exception;
}
消息属性
summary.api=Get List Of Definitions API
dp.length.fail.msg=Minimum length should be {min}
当我运行应用程序并检查时,swagger 不理解要从messages.properties 替换的令牌。
虽然它适用于验证消息。对于dp.length.fail.msg
少于 7 个字符的输入,从 messages.properties 中提供准确信息,如下图所示。
但是在 swagger-ui 的情况下summary.api
是不可读的。
是否可以在界面中读取 messages.properties 键?
解决方案
推荐阅读
- mysql - 使用条件删除 MySQL 中的重复行
- python-3.x - 如何修复 wxPython 模块中的 wxPyDeprecationWarning 警告?
- python - 如何从具有多个索引的数据系列中删除一个值?
- javafx - 在组合框中设置全屏
- python - 如何通过 pandas.factorize 识别多条件?
- reactjs - 如何将materialize-css与react一起使用并保持materialize-css的已安装组件的大小最小
- android - 为什么复选框文本没有通过 android:text 出现,有什么原因吗?
- php - 如何在带有重音数据库的数据表中使用标签类?
- computer-vision - 我可以/如何在应用程序中实现对象识别吗?
- angular - 在 ngOnDestroy 中调用的 destroy() 抛出无法读取未定义的属性“forExport”