@Controller
@RequestMapping("paramter")
public class ParamterController {
@Autowired
private IParamterService service;
@ResponseBody
@RequestMapping(value = "findParamterByPid",method = RequestMethod.GET)
public Map<String,Object> findParamterByPid(String pid){
Map<String, Object> map = new HashMap<>();
List<Paramter> paramterByPid = service.findParamterByPid(pid);
StringBuffer stringBuffer=new StringBuffer();
stringBuffer.append("<option value='' selected>请选择</option>");
for (Paramter paramter: paramterByPid
) {
stringBuffer.append("<option value=\""+paramter.getId()+"\">"+paramter.getName()+"</option>");
}
map.put("s2Str",stringBuffer.toString());
map.put("s3Str",stringBuffer.toString());
return map;
}
@RequestMapping(value = "tolist",method = RequestMethod.GET)
public ModelAndView toList(String pid){
ModelAndView modelAndView = new ModelAndView();
List<Paramter> paramterByPid = service.findParamterByPid(pid);
StringBuffer stringBuffer=new StringBuffer();
//拼接第一个下拉菜单
stringBuffer.append("<select id='s1' οnchange='findcity()'>");
stringBuffer.append("<option value=\"\" selected>请选择</option>");
for (Paramter paramter: paramterByPid
) {
System.out.println(paramter);
stringBuffer.append("<option value=\""+paramter.getId()+"\">"+paramter.getName()+"</option>");
}
stringBuffer.append("</select>");
//拼接第二个下拉菜单
stringBuffer.append("<select id=\"s2\" οnchange=\"findqu()\">\n" +
" <option value=\"\" selected>请选择</option>\n" +
"\n" +
"</select>");
//拼接第三个下拉菜单
stringBuffer.append("<select id=\"s3\" οnchange=\"findjie()\">\n" +
" <option value=\"\" selected>请选择</option>\n" +
"\n" +
"</select>");
modelAndView.addObject("s1Str",stringBuffer.toString());
modelAndView.setViewName("list");
return modelAndView;
}
}
controller中拼接list
最新推荐文章于 2022-05-27 16:59:34 发布