我在构造函数中有这样的带有 lambda 的枚举
enum class EventType(
val getInfoBlocks: (Book, AuditEntity?) -> List<InfoBlock>? = { _, _ -> emptyList() }
) {...}
Run Code Online (Sandbox Code Playgroud)
现在我像这样使用这个 lambda 函数:
data = it.getInfoBlocks.invoke(deal, null)
Run Code Online (Sandbox Code Playgroud)
我可以不用 null 吗?有没有办法为 null lambda 函数参数设置默认值?
我需要添加@ControllerAdvice类来处理异常并返回带有来自异常的消息的正文。
但是,当通过邮递员检查时,即使我的 ControllerAdvice 类方法内的断点触发,我仍然会收到带有 500Internal Server Error 的默认正文。
控制台日志:
WARN 24909 --- [nio-8081-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Failure in @ExceptionHandler com.javalibrary.controller.ControllerAdvice#handleApplicationException(RuntimeException)
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:315) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:219) ~[spring-webmvc-5.3.18.jar:5.3.18]
Run Code Online (Sandbox Code Playgroud)
响应正文:
WARN 24909 --- [nio-8081-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Failure in @ExceptionHandler com.javalibrary.controller.ControllerAdvice#handleApplicationException(RuntimeException)
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:315) ~[spring-webmvc-5.3.18.jar:5.3.18]
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:219) ~[spring-webmvc-5.3.18.jar:5.3.18]
Run Code Online (Sandbox Code Playgroud)
我的ControllerAdvice课:
{
"timestamp": "2022-04-18T19:13:14.183+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/api/v1/book/1"
}
Run Code Online (Sandbox Code Playgroud)
build.gradle插件:
plugins {
id 'org.springframework.boot' version '2.6.6'
id …Run Code Online (Sandbox Code Playgroud) 有谁知道如何为 MAC OS 禁用 Google Chrome 自动更新?
我试过:
GoogleSoftwareUpdate文件夹defaults write com.google.Keystone.Agent checkInterval 0终端中的命令它对我不起作用。
我有Map<Nominal, Integer>对象及其计数的地图:
a -> 3
b -> 1
c -> 2
Run Code Online (Sandbox Code Playgroud)
我需要从中得到这样的List<Nominal>:
a
a
a
b
c
c
Run Code Online (Sandbox Code Playgroud)
如何使用 Stream API 执行此操作?
我有这样的代码:
String regexp = "[\\w\\W]*(London)[\\w\\W]*(Paris)[\\w\\W]*";
String test1 = "London Paris";
boolean t1 = Pattern.matches(regexp, test1);
System.out.println(t1);
String test2 = "London to Paris";
boolean t2 = Pattern.matches(regexp, test2);
System.out.println(t2);
String test3 = "from London to Paris";
boolean t3 = Pattern.matches(regexp, test3);
System.out.println(t3);
String test4 = "from (London) -> (Paris)";
boolean t4 = Pattern.matches(regexp, test4);
System.out.println(t4);
Run Code Online (Sandbox Code Playgroud)
我需要所有布尔值都是真的。现在,这个条件已经满足,但是正则表达式在我看来并不是很有效。我怎样才能改变这个?
我有这样的data class:
data class BookObject(
val description: String?,
val owningCompanyData: OwningCompanyData?,
) {
var id: String? = null
var createdAt: Instant? = null
var createdBy: String? = null
var modifiedAt: Instant? = null
fun update(command: CreateOrUpdateBookObjectCommand): BookObject =
this.copy(
description = command.description,
owningCompanyData = command.owningCompanyData
)
}
Run Code Online (Sandbox Code Playgroud)
当我对update具有完全填充字段的对象使用该函数时,我得到一个具有空id, createdAt, createdBy,modifiedAt字段的对象(它们等于null)。但为什么会出现这种情况呢?为什么这些领域失去了它们的价值?
使用 copy() 函数复制对象,允许您更改其某些属性,同时保持其余属性不变。
java ×3
kotlin ×2
auto-update ×1
collections ×1
lambda ×1
macos ×1
rest ×1
spring-boot ×1
stream ×1