springmvc 在前端jsp页面,select标签显示复合条件。和 session跨页面操作。
在jsp的select标签中,显示一个级联且带有复合查询的结果的select标签。
方法是,在这个类中,定义一个字段,extend,然后把他的get属性,重写为需要的业务
如下
private String extend; public String getExtend() { return this.zhouyiIndex.getName() + "卦 "+this.yaoId+"爻:"+this.yaoContent.substring(0,this.yaoContent.length()>20?20:this.yaoContent.length()); } public void setExtend(String extend) { this.extend = extend; }
然后再在前台的jsp页面中调用即可。
<form:select path="zhouyiYao.id" class="form-control" id="zhouyiYao" > <form:options items="${zhouyiYao}" itemValue="id" itemLabel="extend"></form:options> </form:select>
第二个问题,如果需要定义session跨页面操作。
首先,在这个类上添加@SessionAttributes("")的标签,有s。
@Controller @SessionAttributes("authorId") public class ZhouyiContentController {
然后在需要的添加的authorId属性写入map中,或者ModelAndView,中,只有键值对对应,就可
@RequestMapping("/getContentsByAuthor/{authorId}")
    public ModelAndView getContentsByAuthor(@PathVariable("authorId") Integer authorId,@RequestParam(value="pn",defaultValue = "1") Integer pn) {
        ModelAndView mv = new ModelAndView();
        PageHelper.startPage(pn, 12);
        List<ZhouyiContent> zhouyiContentsByAuthor = zhouyiContentService.getZhouyiContentsByAuthor(authorId);
        PageInfo page = new PageInfo<ZhouyiContent>(zhouyiContentsByAuthor, 7);
        mv.addObject("pageinfo", page);
        mv.addObject("authorId",authorId);  //关键的session保存。键对应。
        mv.setViewName("zhouyiContent");
        return mv;
    }
然后再在需要的类引入上,加入这个@SessionAttribute(“”)的注解,没有s
@RequestMapping("/zhouyiContentAdd")
    public ModelAndView zhouyiContentAdd(ZhouyiContent zhouyiContent,@SessionAttribute("authorId") Integer authorId){
        ModelAndView mv = new ModelAndView();
        mv.addObject("zhouyiAuthor", zhouyiAuthorService.getZhouyiContentAuthorById(authorId));
        mv.addObject("zhouyiYao",zhouyiYaoService.getZhouyiYaos() );
        mv.setViewName("zhouyiContentAdd");
        return mv;
    }
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号