Tôi đang sử dụng mvc mùa xuân. Và tôi không thể lấy param từ url khi method = post. Nhưng khi tôi thay đổi phương pháp để GET, vì vậy tôi có thể nhận được tất cả các param.làm thế nào để có được param trong phương pháp bài mùa xuân mvc?
Đây là hình thức của tôi:
<form method="POST" action="http://localhost:8080/cms/customer/create_customer" id="frmRegister" name ="frmRegister" enctype="multipart/form-data">
<input class ="iptRegister" type="text" id="txtEmail" name="txtEmail" value="" />
<input class ="iptRegister" type="password" id="txtPassword" name="txtPassword" value="" />
<input class ="iptRegister" type="text" id="txtPhone" name="txtPhone" value="" />
<input type="button" id="btnRegister" name="btnRegister" value="Register" onclick="" style="cursor:pointer"/>
</form>
Đây là bộ điều khiển của tôi:
@RequestMapping(value= "/create_customer", method = RequestMethod.POST)
@ResponseBody
public String createCustomer(HttpServletRequest request,
@RequestParam(value="txtEmail", required=false) String email,
@RequestParam(value="txtPassword", required=false) String password,
@RequestParam(value="txtPhone", required=false) String phone){
ResultDTO<String> rs = new ResultDTO<String>();
rs.setStatus(IConfig.SHOW_RESULT_SUCCESS_ON_MAIN_SCREEN);
try{
Customer c = new Customer();
c.setEmail(email);
c.setPassword(password);
c.setPhone(phone);
customerService.insert(c);
rs.setData("Insert success");
}catch(Exception ex){
log.error(ex);
rs.setStatus(IConfig.SHOW_RESULT_ERROR_ON_MAIN_SCREEN);
rs.setData("Insert failure");
}
return rs.toString();
}
Làm thế nào tôi có thể giải quyết này?
Bạn đặt các thông số đó trong biểu mẫu trong JSP của bạn như thế nào? Bạn có thể hiển thị thêm một số mã đó không? – adarshr