• java 前台使用枚举方法(一)


    枚举值封装:

    http://blog.csdn.net/hanjun0612/article/details/72845960


    一  基本类型

    这里接着说前台调用枚举值。


    首先,controller层

    读取对应的状态1,放入modelmap

    @Controller
    @RequestMapping("test")
    public class TestController extends TestBaseController {
    
        @RequestMapping(value = "test1.do")
        public ModelAndView test1(HttpServletRequest request, HttpServletResponse response, ModelMap mode) throws Exception {
            mode.addAttribute("item", 1);
            return new ModelAndView("test/test");
        }
    
    
    }

    前台显示:

    <%@ page import="com.sanju.sanjuSCM.utils.EnumHelper" %>
    <%@ page import="com.sanju.sanjuSCM.model.EnumList.EnumList" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%=EnumHelper.getEnumItem(EnumList.IsDeleteEnum.class, Integer.valueOf((Integer) request.getAttribute("item"))).getItemCN()%>
    <%=EnumHelper.getEnumItem(EnumList.IsDeleteEnum.class, Integer.valueOf((Integer) request.getAttribute("item"))).getItemEN()%>
    </body>
    </html>


    至此,我们也了解了。其实

    mode.addAttribute("item", 1);

    只是将数据放入了request.getAttribute("item")中。

    前台可以通过这个方法获取到,并且通过前一篇  http://blog.csdn.net/hanjun0612/article/details/72845960  的枚举操作方法,来转换对应的中英文



    二  泛型集合


    Controller:

    @Controller
    @RequestMapping("test")
    public class TestController extends TestBaseController {
    
        @RequestMapping(value = "test1.do")
        public ModelAndView test1(HttpServletRequest request, HttpServletResponse response, ModelMap mode) throws Exception {
            List<SysUser> list=new ArrayList<SysUser>();
            SysUser u1=new SysUser();
            u1.setAccount("a");
            u1.setUsernamecn("Testa");
            u1.setIslock(1);
            list.add(u1);
    
            SysUser u2=new SysUser();
            u2.setAccount("b");
            u2.setUsernamecn("Testb");
            u2.setIslock(0);
            list.add(u2);
            mode.addAttribute("list", list);
            return new ModelAndView("test/test");
        }
    
    }

    JSP:

    1 使用:<%%>解决

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr class="tr1">
            <th>账号</th>
            <th>姓名</th>
            <th>状态</th>
        </tr>
        <%
            for(SysUser v:(List<SysUser>)request.getAttribute("list")){
                %>
        <tr>
        <td><%=v.getAccount()%></td>
        <td><%=v.getUsernamecn()%></td>
        <td><%=EnumHelper.getEnumItem(EnumList.IsDeleteEnum.class, v.getIslock()).getItemCN()%></td>
        </tr>
        <%
            }
        %>
    
    </table>


    2 使用 : EL表达式

    <%int i=0;%>
        <c:forEach items="${list}" var="item">
            <tr class="tr1">
                <td>${item.account}</td>
                <td>${item.usernamecn}</td>
                <td><%=EnumHelper.getEnumItem(EnumList.IsDeleteEnum.class, ((List<SysUser>)request.getAttribute("list")).get(i).getIslock()).getItemCN()%></td>
            </tr>
            <%i++;%>
        </c:forEach>





  • 相关阅读:
    div+css简写原则
    并发控制
    div+css之块级元素与内联元素
    window.event对象属性(转)
    SQL SERVER 架构管理
    关系的规范化
    js常用事件
    物联小白CoAP协议
    图片不停的横滚
    DropDownlist编程问题
  • 原文地址:https://www.cnblogs.com/hanjun0612/p/9779800.html
Copyright © 2020-2023  润新知