zoukankan      html  css  js  c++  java
  • 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;
        }
  • 相关阅读:
    IE浏览器版本的判断
    Ajax中的同步和异步
    linq之多表连接
    C#中const 和 readonly 修饰符的用法详解
    sql中的分页实现
    JS中的编码,解码类型及说明
    HttpContext概念讲解
    VS语法书写提示
    c#版本23个设计模式
    批处理 使用默认浏览器 打开html文件
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/12205799.html
Copyright © 2011-2022 走看看