我正在使用spring boot来编写api,我想将所有资源映射到公共基本路径(在这种情况下为/ api).但是,我不想注释每个RestController类来执行此操作(例如,通过使用@RequestMapping进行注释).我已经考虑过以下解决方案,但它们都有一个我不想要的缺点:
所以有人知道如何做到这一点,没有我总结的解决方案的缺点.该项目将仅暴露基于REST的后端,并且不会为任何静态内容提供服务(不知道这是否会影响可能的解决方案).Restcontrollers也分为多个包.
谢谢.
我试图使用角度,eslint:推荐和茉莉花插件推荐设置lint我的角度代码.但是我得到的不是茉莉花的错误.我的eslint文件看起来像这样:
{
"plugins": ["jasmine"],
"extends": ["angular", "eslint:recommended",
"plugin:jasmine/recommended"],
"rules": {
"quotes": [ 2, "single"],
"strict": [2, "global"],
"semi": ["error", "always"],
"angular/on-watch": "warn"
}
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
3:1错误'describe'未定义no-undef
4:5错误'it'未定义no-undef
5:9错误'expect'未定义no-undef
7:5错误'it'未定义no-undef
8:9错误'expect'未定义no-undef
而在我的package.json
我有版本2.3.0
的eslint
和1.8.1
为eslint-plugin-jasmine
.我也有0.5.0
for eslint-config-angular
和1.0.0
for的版本eslint-plugin-angular
.
我也试过没有"plugins": ["jasmine"]
在我的eslint
文件中指定,但后来我得到一个错误,告诉我茉莉花规则没有定义(例如Definition for rule 'jasmine/no-focused-tests' was not found
).
我正在开发一个使用 spring-data-elasticsearch 进行数据存储的应用程序。我也在使用 kotlin 编写这个应用程序。这有一些特殊的怪癖,其中之一是 jackson 需要 jackson-module-kotlin (摆脱没有 args 构造函数的问题)。我还使用了 jackson-datatype-jsr310 模块。
Spring boot 足以从类路径中选取这些模块并自动注册它们。我还将 write-dates-as-timestamps 选项设置为 false。然而 spring-data-elasticsearch 似乎没有注意到它。我认为这是因为 DefaultEntityMapper 消息对象映射器并且不使用 spring 上下文中的对象映射器。我想知道为什么?我通过提供一些额外的配置来修复它,以确保 spring-data-elasticsearch 使用我从 spring 上下文中获得的对象映射器:
@Configuration
open class ElasticsearchConfig(val elasticsearchEntityMapper: ElasticsearchEntityMapper) {
@Bean
open fun elasticsearchTemplate(client: Client) = ElasticsearchTemplate(client, DefaultResultMapper(elasticsearchEntityMapper))
}
@Component
class ElasticsearchEntityMapper(val objectMapper: ObjectMapper) : EntityMapper {
override fun mapToString(`object`: Any?) = objectMapper.writeValueAsString(`object`)
override fun <T : Any?> mapToObject(source: String?, clazz: Class<T>?) = objectMapper.readValue(source, clazz)
}
Run Code Online (Sandbox Code Playgroud)
有没有更好/更简单的方法来确保 spring-data-elasticsearch 使用上下文中的对象映射器?
我在榆树的联合类型中缠绕着一些麻烦.我理解简单的用例就像
type Visibility = All | Active | Completed
Run Code Online (Sandbox Code Playgroud)
这意味着Visiblity的值可以是All,Active或Completed.到现在为止还挺好.然而,我感到困惑的地方
type Msg
= OnFetchMails (WebData (List Mail))
| OnFetchSmss (WebData (List SMS))
Run Code Online (Sandbox Code Playgroud)
我该怎么解释这个?这是否意味着Msg可以是类型函数OnFetchMails,它采用类型函数WebData来获取邮件列表?或者我该如何解释?我认为那(WebData (List Mail))
不是有效载荷吗?
有趣的是,我可以在不了解它的情况下让它工作
我正在使用Spring hateoas来生成HAL接口.我的代码看起来像这样:
@RequestMapping(method = RequestMethod.GET)
public Resources<Resource<Type>> all() {
List<Resource<Type>> sdf = typeRepository.all().stream().map(type -> {
return new Resource<Type>(type, ControllerLinkBuilder.linkTo(this.getClass()).slash(type.getId()).withSelfRel());
}).collect(Collectors.toList());
Resources<Resource<Type>> resourcesType = new Resources<>(sdf);
resourcesType.add(ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(this.getClass()).all()).withSelfRel());
return resourcesType;
}
Run Code Online (Sandbox Code Playgroud)
生成的json看起来像这样:
{
"_links": {
"self": {
"href": "http://localhost:8080/type"
}
},
"_embedded": {
"typeEntityList": [
{
"id": "4f7fa2da-20e2-4b42-9b45-2d1749825785",
"version": 0,
"name": "name1",
"_links": {
"self": {
"href": "http://localhost:8080/type/4f7fa2da-20e2-4b42-9b45-2d1749825785"
}
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我想更改"typeEntityList"的名称,但我无法找到它的来源或来源.谁知道怎么样?
spring ×2
angularjs ×1
elm ×1
eslint ×1
jasmine ×1
kotlin ×1
rest ×1
spring-boot ×1
spring-data ×1
union-types ×1