我是使用 Play2 框架的新手。这是我写的一个简单的控制器
package controllers;
import play.*;
import play.mvc.*;
import views.html.*;
import models.*;
import java.util.*;
import play.libs.Json;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class Users extends Controller {
@BodyParser.Of(BodyParser.Json.class)
public static Result register() {
JsonNode json = request().body().asJson();
String firstName=json.findPath("first_name").asText();
String lastName=json.findPath("last_name").asText();
String mobileNumber=json.findPath("mobile").asText();
String address=json.findPath("address").asText();
String userName=json.findPath("user_name").asText();
String password=json.findPath("password").asText();
ObjectNode result = Json.newObject();
result.put("status", "FAILIURE");
result.put("message", "Missing parameter [name]");
return ok("meow");
}
public static Result login() {
return TODO;
}
public static Result logout(final Long id) {
return TODO;
}
}
我正在卷曲
curl -i -H "Accept: application/json" -X PUT -d "{"first_name": "simon","last_name": "bolliver","mobile": "12345","address": "23 Donwton","user_name": "simon","password": "levy"}" http://localhost:9000/user/register
我在第二行收到 NullPointerException。我究竟做错了什么 ?