我想生成一个动态网址,例如 http://example.com/path/to/page?name=ferret&color=purple
我可以将名称和颜色两个单独的输入字段从我的表单发送到控制器作为单个参数。有人可以帮我编写相应的jsp和spring控制器编码。
以下是我的控制器:
@RequestMapping(value = "/ws/jobs/{title}/{location}/{experience}")
public ModelAndView openRequirementsRedirect(JobSearchRequest jobSearchRequest) throws Exception{
ModelAndView model = new ModelAndView();
model.addObject("title", jobSearchRequest.getTitle());
model.addObject("location", jobSearchRequest.getLocation());
model.addObject("experience", jobSearchRequest.getExperience());
model.setViewName("openJobs/openjobs");
return model;
}
我有 pojo :
public class JobSearchRequest {
private String title;
private String location;
private String experience;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getExperience() {
return experience;
}
public void setExperience(String experience) {
this.experience = experience;
}
}
和 y jsp 调用是这样的:
window.location.href = example+"/abc?&title="+title+"&location="+location+"&experience="+experience;