我正在尝试使用以下模式:
enum Option {
ONE = 'one',
TWO = 'two',
THREE = 'three'
}
interface OptionRequirement {
someBool: boolean;
someString: string;
}
interface OptionRequirements {
[key: Option]: OptionRequirement;
}
Run Code Online (Sandbox Code Playgroud)
这对我来说似乎很简单,但是出现以下错误:
索引签名参数类型不能为联合类型。考虑改用映射对象类型。
我究竟做错了什么?
我有一个POJO:
public class Foo {
public String getValue(Integer arg0, BigDecimal arg1) {...}
}
Run Code Online (Sandbox Code Playgroud)
我将它作为Spring MVC的模型参数放入JSP中,并尝试使用它:
<c:set var="ans" value="${foo.getValue(null, null)}"/>
Run Code Online (Sandbox Code Playgroud)
但在getValue方法上
arg0 = 0
arg1 = 0
Run Code Online (Sandbox Code Playgroud)
而不是预期的
arg0 = null
arg1 = null
Run Code Online (Sandbox Code Playgroud)
我试图在Tomcat 7.0.40和jetty 9.0.3上运行它
它是一些Tomcat bug,还是EL工作的正确方式?如何在EL中调用带有null参数的方法?
更新1: 几个来源和文档(http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html)说添加JVM属性
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
Run Code Online (Sandbox Code Playgroud)
解决它.
但是当我设定它时,没有任何事情发生.我把它设置正确
System.getProperty("org.apache.el.parser.COERCE_TO_ZERO")`
Run Code Online (Sandbox Code Playgroud)
"false"在运行时返回)
可能是Tomcat需要一些其他设置来改变使用这个参数...
我尝试在gulp 4中启动任务之前清理文件夹
var gulp = require('gulp');
var del = require('del');
gulp.task('clean', function() {
del.sync('folder/*');
});
gulp.task('foo', gulp.series('clean', 'something'));
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为'clean'任务必须返回一些流.我找到了解决方法:
gulp.task('clean', function() {
del.sync('folder/*');
var emptyStream = gulp.src([]).pipe(gulp.dest('/'));
return emptyStream;
});
Run Code Online (Sandbox Code Playgroud)
,但仍希望找到更好的解决方案.
我在 ktor-client 文档和示例中发现几乎无处不在,他们使用空的 formData 来展示客户端的工作方式
formParameters: Parameters = Parameters.Empty
Run Code Online (Sandbox Code Playgroud)
那么 kotlin/ktor 用什么方法来填充参数呢?
我尝试使用 Converter 在 Spring MVC 中组织表单绑定,就像这里描述的那样:Spring 表单绑定怎么做?无法将 [java.lang.String] 类型的值转换为所需的 type,但我错过了一些东西,并且绑定不起作用。
一些片段:
实体:
public class Building {
private Long id;
private String address;
private BankAccount mainIncomeBankAccount;
// ... getters, setters, hashCode() and equals()
}
public class BankAccount {
private Long id;
private String accountNumber;
// ... getters, setters, hashCode() and equals()
}
Run Code Online (Sandbox Code Playgroud)
JSP:
<form:form commandName="building" action="" method="post">
<form:input type="text" path="address"/>
<form:select path="mainIncomeBankAccount">
<form:option label="-- null value --" value="${null}"/>
<form:options items="${bankAccounts}" itemLabel="accountNumber" itemValue="id"/>
</form:select>
<input type="submit"/>
</form:form>
Run Code Online (Sandbox Code Playgroud)
控制器:
@RequestMapping(value="/edit", method …Run Code Online (Sandbox Code Playgroud) 有没有一种好方法可以检查未完成的 Observable 在那个确切时间是否为空?
let cache = new ReplaySubject<number>(1);
...
// Here I want to know if 'cache' still empty or not. And, for example, fill it with initial value.
cache.isEmpty().subscribe(isEmpty => {
if (isEmpty) {
console.log("I want to be here!!!");
cache.next(0);
}
});
// but that code does not work until cache.complete()
Run Code Online (Sandbox Code Playgroud) 我在 *ngFor 语句中调用函数:
@Component({
selector: 'foo-view',
template: '<div *ngFor="let foo of loadAll() | async"></div>'
})
export class FooComponent {
loadAll() : Observable<Foo[]> {
return this.http.get(`api/foos`)
.map(response => response.json() as Foo[]);
}
}
Run Code Online (Sandbox Code Playgroud)
当代码启动时,它会一遍又一遍地无限循环发送 http 请求。
为什么?我该怎么做才能避免这种情况?
PS我知道标准的解决方法
@Component({
selector: 'foo-view',
template: '<div *ngFor="let foo of foos"></div>'
})
export class FooComponent implements OnInit {
foos: Foo[] = [];
ngOnInit() {
loadAll().subscribe(foos => this.foos = foos);
}
loadAll() : Observable<Foo[]> {
return this.http.get(`api/foos`)
.map(response => response.json() as Foo[]);
}
}
Run Code Online (Sandbox Code Playgroud)
但我正在寻找删除多余变量的方法。
我需要一个全局计数器和函数来逐个返回数字.例如,我希望这个脚本回显6,7,8(但它回显6,6,6):
#!/bin/bash
port_counter=5
function get_free_port {
port_counter=$((port_counter + 1))
echo ${port_counter}
}
function foo {
echo $(get_free_port)
}
foo
foo
(foo;)&
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得6,7,8?
更新:
好的,在chepner的回答后,我需要指出一点我的问题.如果我需要使用get_free_port变量foo,我不能使用这种方法,不是吗?所以我不能写
function foo {
variable=get_free_port # variable=$(get_free_port) was ok, but returns 6,6,6
echo ${variable}
}
Run Code Online (Sandbox Code Playgroud)
而且foo &- 像用法一样是不可取的
我正在使用 ktor-client (ApacheHttpClient 引擎)创建简单的 HTTP 请求
val client = HttpClient(Apache) {
engine {
followRedirects = false
this@HttpClient.expectSuccess = false
}
}
Run Code Online (Sandbox Code Playgroud)
并用它来提交表单
client.submitForm<HttpResponse>(
url = "https://foo.com/login",
formParameters = Parameters.build {
append("_username", username)
append("_password", password)
})
Run Code Online (Sandbox Code Playgroud)
在日志中,我可以看到带有 302 重定向的正确响应,我想从中获取并获取 cookie。但相反,我看到客户端继续前进并发出更多请求,最终失败:
io.ktor.client.features.SendCountExceedException:超出最大发送计数 20
如何在 ktor-client 中完全禁用基于 302 的重定向?
javascript ×3
kotlin ×3
typescript ×3
httpclient ×2
java ×2
ktor ×2
rxjs ×2
spring-mvc ×2
angular ×1
asynchronous ×1
bash ×1
data-binding ×1
el ×1
gulp ×1
rxjs5 ×1
scope ×1
spring ×1
tomcat ×1