이 A 급Spring Mongo db를 사용하여 기존 List에 객체를 추가하는 방법은 무엇입니까?
@Document
class User{
private String id ;
private String name;
@Dbref
private List<Socity> Socitys;
}
이며,이 클래스 Socity
@Document
class Socity{
private String id ;
private String name;
}
이며,이
public User addUser(User user) {
List<Socity> socity = new ArrayList<>();
user.setsocitys (socity);
return userRepository.save(user);
}
내가 기존 사용자 에 socity를 추가하려면 사용자 추가 기능입니다 나는 이것을 시도하지만 작동하지 않는다.
이 (3210)은 DB에 변경 사항을 지속 userRepository.save(u)
를 추가 나머지 서비스 코드의 끝에서
@RequestMapping(value = "up/{id}", method = RequestMethod.POST ,produces =
"application/json")
public User addSocityToUser(@RequestBody Socity, @PathVariable String id)
{
return SocityDAO.addSocityToUser(e, id);
}
덕분에 작동합니다! –
우편 배달부와 함께 휴식 서비스를 테스트하려고 할 때이 오류가 발생합니다. "문서를 읽을 수 없습니다. START_ARRAY 토큰 \ n의 인스턴스를 deserialize 할 수 없습니다. \ n –
에 @Oo 전체 스택 추적없이 코드를보고 대답하기가 어렵습니다. 서비스. 또한 그것은 다른 문제이므로 더 나은 당신이 현재 전체 코드 및 스택 추적을 사용하여 새 질문을 열면. – Tom