我想为一个新的Java Spring Boot应用程序创建一个自定义的json响应。现在,我只想创建一个虚拟的json对象--开始控制输出json响应的结构。
当我这样做时,它想要创建.puts的cast前缀--我曾经使用Mongodb -- BasicDBObject --但是现在我这里没有mongo。
DBObject obj = new BasicDBObject();
obj.put( "foo", "bar" );我该怎么做呢?
--
@RequestMapping(value = "/login", method = RequestMethod.GET)
@CrossOrigin(origins = {"*"})
public ResponseEntity<?> login(
@RequestParam(value="email", required=false, defaultValue="email") String email,
@RequestParam(value="password", required=false, defaultValue="password") String password,
HttpServletRequest request
) throws Exception {
Object response = new Object();
response.put("information", "test");
response.put("id", 3);
response.put("name", "course1");
return new ResponseEntity<>(response, HttpStatus.OK);
}发布于 2017-09-05 09:29:14
**@ResetController** // add this
public class YourClass{
@RequestMapping(value = "/login", method = RequestMethod.GET)
@CrossOrigin(origins = {"*"})
public ResponseEntity<?> login(){
Object response = new Object();
response.put("information", "test");
response.put("id", 3);
response.put("name", "course1");
return new ResponseEntity<>(response, HttpStatus.OK);
}
}https://stackoverflow.com/questions/46045703
复制相似问题