springmvc值的传递(从后台到前台)

///1直接跳转页面的回写不是ajax的调(只用@RequestMapping)

control中
1,model.addObject("parentMenus", parentMenus);   ///////////////////////////////////////////////////////////////一个key,对应对个value


2,model.addAttribute



@RequestMapping(value = "/edit")
    public void edit(Long id,Model model) {

        if (id != null) {
        User roledetl = userService.getUserForEditById(id);
            model.addAttribute("roledetl", roledetl);
           List<Organization> orgs=  organizationService.getOrganization();
            model.addAttribute("orgs", orgs);
//            model.addAttribute("areas", acountService.getDictDataListByTypeCodeAndParentId(StaticUtil.PROVINCE_CITY, organization.getCityId()));
        }
//        model.addAttribute("provinces", acountService.getDictDataListByTypeCode(StaticUtil.PROVINCE_CITY));
//        model.addAttribute("roledetl",null);
    }


方法二    model.addObject("parentMenus", parentMenus);   //////
/////////////////////////////////////////////////////////一个key,对应对个value

<c:forEach items="${parentMenus}" var="parent">
        <c:choose>
            <c:when test="${parent.isleaf=='0'}">
                <div class="titleArea_normal" ><i class="icon_spgl"></i>${parent.menuName}</div>
                <div class="box3" style="display: none">
                    <c:forEach items="${parent.childs}" var="item">
                        <c:choose>
                            <c:when test="${!empty item.url}">
                                <a class="list" href="${pageContext.request.contextPath}${item.url}" target="mainFrame"><span>${item.menuName}</span></a>
                            </c:when>
                            <c:otherwise>
                                <a   class="list" href="javascript:void(0)" target="mainFrame"><span>${item.menuName}</span></a>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </div>

            </c:when>
            <c:when test="${parent.isleaf=='1'}">
                <a class="titleArea_normal  firstShow"  href="${pageContext.request.contextPath}${parent.url }" target="mainFrame"><i class="icon_home1"></i>${parent.menuName}<input type="hidden"/></a>
            </c:when>
        </c:choose>
    </c:forEach>


====================================================================
jsp中

<%--  <c:choose>
                        <c:when test="${roledetl.status==1}">
                        <input class="width_240" name="status"   value=" 有效" />
                        </c:when>
                         <c:when test="${roledetl.status==0}">
                        <input class="width_240" name="status"   value=" 无效" />
                        </c:when>
                       </c:choose> --%>
                      <%--  <c:if test="${roledetl.status==1}">
                       <input class="width_240" name="status"   value=" 有效" />
                       </c:if> --%>
                        <select name="status" class="width_240">
                                <option value="1" <c:if test="${roledetl.status==1}">selected="selected"</c:if>>有效</option>
                                <option value="0" <c:if test="${roledetl.status==2}">selected="selected"</c:if>>无效</option>
                         </select>
                         <select name="status" class="width_240">
                                <option value="0" selected="selected">===请先选择===</option>
                                <c:forEach items="${item}" var="item" >
                                <option value="${item.id }" selected="selected">${item.name }</option>
                                </c:forEach>
                         </select>


==========================================================
实例,注意引入jstl标签


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>



<td><select name="org" class="width_240">
                                <option value="0" selected="selected">===请先选择===</option>
                                <c:forEach items="${orgs}" var="item" >
                                <option value="${item.id }" >${item.orgName }</option>
                                </c:forEach>
                         </select>
                         </td>

@RequestMapping(value = "/edit")
    public void edit(Long id,Model model) {

        if (id != null) {
        User roledetl = userService.getUserForEditById(id);
            model.addAttribute("roledetl", roledetl);
           List<Organization> orgs=  organizationService.getOrganization();
            model.addAttribute("orgs", orgs);
//            model.addAttribute("areas", acountService.getDictDataListByTypeCodeAndParentId(StaticUtil.PROVINCE_CITY, organization.getCityId()));
        }
//        model.addAttribute("provinces", acountService.getDictDataListByTypeCode(StaticUtil.PROVINCE_CITY));
//        model.addAttribute("roledetl",null);
    }

=========================================================

方法三 直接用@ResponseBody  结合ajax,用了这个标签的不会根据路劲跳转,而是和ajax结合回写到回调函数中(方法中的return中的内容)





猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2243027