我一直在研究从 Android 设备使用的 Spring RESTful 应用程序。当我尝试发送 POST 请求时会出现我的问题。我的对象在服务器端收到,但所有属性均为空。
我的控制器:
@Controller
public class BeanController {
@Autowired
private ReservationService reservationService;
@RequestMapping(value = "reservation/add/{dateR}", method = RequestMethod.POST)
public ModelAndView addReservation(@RequestBody Reservation reservation, @PathVariable String dateR) {
Date date = Date.valueOf(dateR);
boolean result = reservationService.saveReservation(reservation,date);
return new ModelAndView("beanXmlView", BindingResult.MODEL_KEY_PREFIX + "reservation", result);
}
}
在我的客户端,我确保设置了对象属性。
我的客户端:
Reservation reservation = new Reservation();
reservation.setDateReservation(Model.date);
reservation.setSalle(Model.salle);
if(Model.selectedEquipements.size() == 0)
reservation.setEquipements(new ArrayList<Equipement>());
else reservation.setEquipements(Model.selectedEquipements);
reservation.setPlagesHoraires(Model.selectedPlageHoraires);
reservation.setUtilisateur(user);
final String url = "http://10.0.2.2:8080/HibernateSpringREST/";
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
// Make the HTTP POST request, marshaling the request to JSON, and the response to a String
restTemplate.postForObject(url + "reservation/add/"+Model.date, reservation, Reservation.class);
有没有人知道可能导致此问题的原因?