我的后端有spring和hibernate,我有一个这样的方法:
@RequestMapping(value = "/update", method = RequestMethod.GET)
public void updateResource(HttpServletRequest request,HttpServletResponse response) throws IOException {
int resource=0;
String cb = request.getParameter("callback");
try {
resource = Integer.parseInt(request.getParameter("resource"));
} catch (NumberFormatException e) {
logger.info(e.getMessage());
Util.getJSONP(cb, false, e.getMessage(), "", response);
return;
}
Resources rs = customerService.getResource(resource);
rs.setFirstName(request.getParameter("firstName"));
rs.setLastName(request.getParameter("lastName"));
rs.setAddress(request.getParameter("address"));
rs.setCity(request.getParameter("city"));
rs.setState(request.getParameter("state"));
rs.setZip(request.getParameter("zip"));
rs.setPhone(request.getParameter("phone"));
rs.setPhoneMobile(request.getParameter("phoneMobile"));
rs.setEmail(request.getParameter("email"));
rs.setImage(request.getParameter("image"));
rs.setLastUpdate(new Date());
String dobString = request.getParameter("dob");
if (Util.validateDate(dobString)) {
rs.setDob(Util.getDate(dobString));
}
else{
logger.info("Invalid Format Date");
Util.getJSONP(cb, false, "Invalid format date", "", response);
return;
}
resourceService.updateResource(rs);
Util.getJSONP(cb, true, "success", "", response);
}
新要求是您可以添加图像。 前端是用Sencha Touch制作的,它在base64给我发了一张照片。 我已经读过,我必须将我的方法GET更改为POST。 我将我的方法改为POST,但它无法正常工作。
我的模特:
@Entity
@Table(name="resource")
public class Resources {
@Id
@Column(name="resource_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int resourceId;
@Column(name="first_name",length=45)
private String firstName;
@Column(name="last_name",length=45)
private String lastName;
@Column(name="phone",length=20)
private String phone;
@Column(name="phone_mobile",length=20)
private String phoneMobile;
@Column(name="address",length=100)
private String address;
@Column(name="zip",length=20)
private String zip;
@Column(name="city",length=30)
private String city;
@Column(name="state",length=30)
private String state;
@Column(name="geox",length=20)
private String geox;
@Column(name="geoy",length=20)
private String geoy;
@Column(name="email",length=150)
private String email;
@Column(name="last_update")
private Date lastUpdate;
@Column(name="dob")
private Date dob;
@Column(name="image", columnDefinition="TEXT")
private String image;