2016-06-07 5 views
0
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) 

ошибка я получил это:Ошибка при попытке извлечь данные из MongoDB на апи отдыха

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 
+0

Просто добавьте конструктор по умолчанию. Поскольку его переопределенный MongoConvertor не может построить объект записи – user1211

+0

Как это сделать? Извините, я новичок в весне. –

ответ

0

Добавить конструктор по умолчанию

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 
} 
Смежные вопросы