我正在使用带有Angular.js客户端的@RestController实现一个spring启动应用程序,我想创建/更新一个或多个用户组(作为子级)。这不适用于多个用户。
模特签名:
Grp {
externalId (string, optional),
grpOwner (User, optional),
grpTxt (string, optional),
users (Array[User], optional)
}
User {
externalId (string, optional),
username (string, optional)
}
grp.json(两个用户都存在于数据库中)
{
"externalId": "G0000001",
"users": [
{
"username": "admin"
},
{
"username": "system"
}
]
})
尝试创建/更新一个具有多个用户的组时,仅考虑第一个用户。实际上,在调试Java部分时。有什么想法吗?
@RequestMapping(method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<Grp> updateGrp(@RequestBody Grp grp) throws URISyntaxException {
log.debug("REST request to update Grp : {}", grp);
// Check if the group has been created
Optional<Grp> oGrp = gDao.findOneByExternalIdAndGrpOwner(grp.getExternalId(), this.getCurrentUser());
if (oGrp.isPresent()) {
Grp mGrp = oGrp.get();
this.merge(mGrp, grp);
Grp result = gDao.save(mGrp);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert("grp", grp.getExternalId().toString()))
.body(result);
}
return createGrp(grp);
}
跟踪:
2016-07-06 11:29:12.563 DEBUG 3216 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing PUT request for [/api/grps]
2016-07-06 11:29:12.566 DEBUG 3216 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /api/grps
2016-07-06 11:29:12.567 DEBUG 3216 --- [nio-8080-exec-5] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<com.coopyrightcode.common.domain.Grp> com.coopyrightcode.common.web.rest.GrpResource.updateGrp(com.coopyrightcode.common.domain.Grp) throws java.net.URISyntaxException]
2016-07-06 11:29:12.604 DEBUG 3216 --- [nio-8080-exec-5] m.m.a.RequestResponseBodyMethodProcessor : Read [class com.coopyrightcode.common.domain.Grp] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@4982ce48]
2016-07-06 11:29:12.613 DEBUG 3216 --- [nio-8080-exec-5] c.c.common.aop.logging.LoggingAspect : Enter: com.coopyrightcode.common.web.rest.GrpResource.updateGrp() with argument[s] = [Grp [grpTxt=null, grpOwner=null, users=[User [username=admin, password=null, fName=null, lName=null, email=null, activated=false, langKey=null, appKey=63d71c52-95cd-43db-9, resetKey=3dfaf9f7-b46d-4daf-9, resetDate=null, usrAccountNonLocked=true, usrAccountNonExpired=true, usrCredentialsNonExpired=true, usrBio=null, usrMobile=null, usrPhone=null, usrPics=null, usrReferent=null, usrCtrId=null]]]]
2016-07-06 11:29:12.613 DEBUG 3216 --- [nio-8080-exec-5] c.c.common.web.rest.PortfolioResource : REST request to update Grp : Grp [grpTxt=null, grpOwner=null, users=[User [username=admin, password=null, fName=null, lName=null, email=null, activated=false, langKey=null, appKey=63d71c52-95cd-43db-9, resetKey=3dfaf9f7-b46d-4daf-9, resetDate=null, usrAccountNonLocked=true, usrAccountNonExpired=true, usrCredentialsNonExpired=true, usrBio=null, usrMobile=null, usrPhone=null, usrPics=null, usrReferent=null, usrCtrId=null]]]