小编ped*_*oso的帖子

PlayFramework 2.2 Java Action Composition

我一直在Play上使用Action组合!直到现在的应用程序,他们工作正常.但是最近的2.2.0更新它们不再起作用,我不知道如何正确更新它们.

这个动作例如:

public class ChatMsgValidation extends Action<ChatMsgValidation.ValidChatMsg> {

@With(ChatMsgValidation.class)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ValidChatMsg {
}


public Result call(Http.Context ctx) throws Throwable {

    Utils.debugFunctionCall("ValidChatMsg() " + ctx.toString());

    // validate we got the "player" parameter
    JsonNode jsonRequest = request().body().asJson();
    if (!WSUtils.validateJSONField(Constants.JSON_MSG, jsonRequest)) {
        return badRequest(WSUtils.simpleMissingFieldMsg(Constants.JSON_MSG));
    }

    RequestParser requestParser = new RequestParser(request());
    String chatMsg = requestParser.getMessage();

    if (chatMsg.isEmpty()) {
        return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.cannot.be.empty.error"), FailConstants.REASON_EMPTY));
    }


    if (chatMsg.length() < Constants.MIN_CHAT_MESSAGE_LENGTH) {
        return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("query.lower.limit.error"), FailConstants.REASON_TOO_SHORT));
    }

    if (chatMsg.length() > Constants.MAX_CHAT_MESSAGE_LENGTH) {
        return badRequest(WSUtils.simpleFailureMsgWithReason(Messages.get("message.too.long.error"), FailConstants.REASON_TOO_LONG));
    } …
Run Code Online (Sandbox Code Playgroud)

java playframework playframework-2.0

6
推荐指数
1
解决办法
2479
查看次数

将行添加到文件开头

我正在尝试在文本文件的开头添加一个新行.我首先打开文件,append但只允许我使用write_all写入文件的末尾,至少这是我得到的结果.如果我正确阅读文档,这是设计的.

我试过玩seek,但这并没有解决它.

这就是我目前所拥有的:

let mut file = OpenOptions::new().append(true).open(&file_path).unwrap();
file.seek(SeekFrom::Start(0));
file.write_all(b"Cool days\n");
Run Code Online (Sandbox Code Playgroud)

如果我打开文件write,我最终会覆盖数据而不是添加.用Rust实现这个目标的合适方法是什么?

io file rust

4
推荐指数
1
解决办法
765
查看次数

Kotlin从Java访问内部类中的常量

注意:自Kotlin 1.0 beta版(至少)以来,此问题已得到解决.由于历史原因,保持其余内容完好无损.


我正在使用Kotlin和Android,我正在尝试使用SDK中的一些常量,如下所示:

MediaRecorder.AudioSource.MIC;
Run Code Online (Sandbox Code Playgroud)

它没有看到AudioSource,因此它也没有看到MIC.我已经尝试更改导入,清理项目.到目前为止没有任何工作.我通过在Java类中导入它来暂时解决它,它运行得很好,然后我只是从我的Kotlin文件中引用我的Java类,但我真的想知道为什么会发生这种情况以及如何避免这样做Java类.

android kotlin

3
推荐指数
1
解决办法
725
查看次数

标签 统计

android ×1

file ×1

io ×1

java ×1

kotlin ×1

playframework ×1

playframework-2.0 ×1

rust ×1