我在Intellij Idea中使用Terminal,有时我发现应该删除刚刚输入的命令。在Windows或Linux中,我可以使用Ctrl + C清除我刚刚输入的命令,在Idea中,我应该按住Delete或BackSpace删除它。Idea中类似的键盘快捷键是什么?或者,如果默认情况下没有人,可以设置它吗?
kotlin中有一个数据类,例如
@Entity
data class Record(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
@Column(nullable = false, name = "name")
var name: String? = null
)
Run Code Online (Sandbox Code Playgroud)
我可以调用component1和component2函数来访问属性.但是,当我声明属性var时,我有getter和setter,如果我声明属性val,我有getter.在这种情况下,componentN函数是多余的,为什么我们需要它们,因为getter似乎更加不言自明?
我正在尝试定义一个战争名称来对应自定义命名约定。当前,生成了2个war文件:app-name.war并且,app-name-boot.war
但是,我想覆盖-boot后缀,例如将war命名为app-name-executable.war。
<finalName>${artifactId}-executable</finalName>
Run Code Online (Sandbox Code Playgroud)
但是随后生成了app-name-executable-boot。那么我如何覆盖可运行战争的引导后缀?
我有以下非常简单的kotlin代码来演示infix函数包com.lopushen.demo.presentation
fun main(args: Array<String>) {
print("Hello " x_x "world")
}
infix fun String.x_x(s: String) {
println("$this x_x $s x_x")
}
Run Code Online (Sandbox Code Playgroud)
而预期的结果是
Hello x_x world x_x
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
下面的实际结果,是什么导致程序打印kotlin.Unit?
Hello x_x world x_x
kotlin.Unit
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud) 我已经开始尝试kotlin并且出现了一个问题我已经声明了一个可变列表的扩展属性并尝试在字符串模板中使用它:
fun main(args: Array<String>) {
val list = mutableListOf(1,2,3)
// here if use String template the property does not work, list itself is printed
println("the last index is $list.lastIndex")
// but this works - calling method
println("the last element is ${list.last()}")
// This way also works, so the extension property works correct
println("the last index is " +list.lastIndex)
}
val <T> List<T>.lastIndex: Int
get() = size - 1
Run Code Online (Sandbox Code Playgroud)
我有以下输出
the last index is [1, 2, 3].lastIndex
the last element is …Run Code Online (Sandbox Code Playgroud) 我有以下代码,这是我的 API 的艺术
import org.springframework.web.bind.annotation.PathVariable;
import io.swagger.annotations.*;
@GetMapping(value = "/{userId}")
public String getUserHistory(ApiParam(value = "The user id")
@PathVariable("userId") Integer userId, Model model) throws NotFoundException {
// fetch user info
model.addAttribute("userInfo", userInfo);
return "userHistory";
}
Run Code Online (Sandbox Code Playgroud)
如果我有@ApiParam 注释,@PathVariable 就变成非必需的,所以如果我不输入 userId 并通过 Swagger UI 发出请求,请求仍然会转到服务器,这会导致不必要的服务器错误。@PathVariable 的“required”参数默认为true(因此,默认值为@PathVariable(name="userId", required = true))并且在没有@ApiParam 的情况下可以正常工作。就我而言,这些注释不应该改变彼此的行为。这是一个 Swagger 错误还是只是误用?