简体   繁体   English

尝试在Rest API上从MongoDB检索数据时出错

[英]Error when trying to retrieve data from mongodb on rest api

public class Record {


private DateTime timestamp;
private String filename;
private String cameraid;


public Record(String timestamp, String filename, String cameraid) {
    this.timestamp = ISODateTimeFormat.dateTime().parseDateTime(timestamp);
    this.filename = filename;
    this.cameraid = cameraid;

}
//Getters & setters

(Model)
-----------------------------------------------------------------------------

public class RecordController {
@Autowired
private RecordRepository rep;

@RequestMapping(value="store")
public  String  camera (@RequestParam(required=true, value="ts") String timestamp,
@RequestParam(value="fn",required=true) String filename,
@RequestParam(value="cam",required=true) String cameraid)

{
    try {
        Record cam = new Record(timestamp,filename,cameraid);

        rep.save(cam);
        return "OK";
    }catch(Exception ex){

        String errorMessage;
        errorMessage = ex + " <== error";
        return ("error: " + ex.getMessage());}

}
@RequestMapping(value="li", method=RequestMethod.GET)
public @ResponseBody List<Record> getAll() {
    return rep.findAll();
}
} (Controller)

----------------------------------------------------------------------------
import org.springframework.data.mongodb.repository.MongoRepository;

public interface RecordRepository extends MongoRepository<Record, String> {
} (Recpository)

the error i got is: 我得到的错误是:

Failed to instantiate hello.Record using constructor public hello.Record(java.lang.String,java.lang.String,java.lang.String) with arguments 2016-06-06T00:19:09.223+08:00,9d9fd7f8f4caec99bce9dff8f4644e41,000000006f4280af

Add a default constructor 添加默认构造函数

public class Record {


private DateTime timestamp;
private String filename;
private String cameraid;

public Record(){} //default constructor

public Record(String timestamp, String filename, String cameraid) {
    this.timestamp = ISODateTimeFormat.dateTime().parseDateTime(timestamp);
    this.filename = filename;
    this.cameraid = cameraid;

}

//getter and setter
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从mongodb检索数据 - Retrieve data from mongodb 尝试通过 REST API 访问 Azure 数据湖存储 Gen 2 中的文件系统时出现 403 错误 - 403 error when trying to access file system in Azure data lake storage Gen 2 via REST API 致命例外:尝试使用 Retrofit 从 API 检索数据时,OkHttp Dispatcher - FATAL EXCEPTION: OkHttp Dispatcher when trying to retrieve data from API using Retrofit 尝试将数据从 spring 应用程序发送到远程服务器上的 mongodb 时出错 - Error when trying to send data from the spring application to mongodb on remote server Springboot - HttpClientErrorException:如果在 MongoDB 中找不到数据,则从另一个 REST API 调用 REST API 的 404 null 将不起作用 - Springboot - HttpClientErrorException: 404 null calling REST API from another REST API is not working if data not found in MongoDB 尝试检索BusinessPartnerUUID时出错 - Error when trying to retrieve BusinessPartnerUUID 尝试从方法检索数据时,变量返回null - Variable returns null when trying to retrieve data from a method 尝试从SQLiteOpenHelper检索数据时出现Android NullpointerException - Android NullpointerException when trying to retrieve data from SQLiteOpenHelper 尝试从Swing中的JTable检索数据时,出现空指针异常 - Null Pointer Exception when trying to retrieve data from JTable in Swing 格式错误的表达式:尝试从哈希图检索值时出现“错误” - Malformed expression :“Error” when trying to retrieve value from hashmap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM