SPRING WEB MVC ANNOTATIONS-部分页面渲染的方法

SPRING WEB MVC ANNOTATIONS-Method for Partial Page Rendering

朋友们大家好,

[需要一些关于 spring 基于 web mvc 注释的帮助:]

如何在 spring web mvc 注释上使用部分页面渲染。

现在,此母版页由下拉列表组成,如果选择 Account,则部分页面 Account 将加载到母版页中名为 CreateEntity。否则,如果 Lead 被选中,那么 Lead 将进入母版页。

我已经创建了名为 CreateEntityController.java 的控制器,并在其中写入了如下代码:

***CreateEntityController.java***
 @RequestMapping(value = { "/CreateEntity" }, method = RequestMethod.GET)  
 public ModelAndView CreateEntity(Model model) {  
 model.addAttribute("module", "Account");  
 model.addAttribute("msg", "This is the partial view page!");                                    
 return new ModelAndView("CreateEntity");
 }

JSP 页面代码: (CreateEntity.jsp)-M翠菊P年龄

<li><c:url value="/CreateEntity" var="CreateEntity"  /> 
                            <a data-params='{"module":"CreateLeadStatus"}'
                                href="<c:out value='${CreateEntity}'/>">Create Entity</a></li>

<div>
    <%@include file="CreateLeadStatus.jsp"%>
</div>

JSP 页面代码 2: *部分页面代码: ***Account.jsp****

 <spring:url value="CreateEntity" var="CreateEntity" />

<form class="form-Account" action="${CreateEntity}" method="POST"  role="form" >
<div class="crmBodyWin" style="">
    <div id="" class="p30 lbox set_mw">
        <div id="secDiv_Lead_Information" class="editParentSection pL30 pR30">
            <table style="width: 100%" cellspacing="0" cellpadding="0"
                id="secHead_Lead_Information">
                <tbody>
                    <tr>
                        <td class="contHeadInfo">Lead Status</td>
                    </tr>
                </tbody>
            </table>

            <div style="width: 100%" class="secContent" border="0"
                cellspacing="1" cellpadding="0" id="secContent_Lead_Information">
                <div class="contInfoTab floatL formViewCreate">
                    <div id="Leads_fldRow_COMPANY" class="textFld COMPANY tabDivCreate">
                        <div class="labelTabCreate pL5 pR newmandatory"
                            id="Crm_Leads_COMPANY_label">Status Name</div><div class="labelValCreate mL45">
                            <input
                                type="text" class="textField" style="width: 100%"
                                id="txtleadname" name="txtleadname" tabindex="5" maxlength="100"
                                data-maxlength="100" data-customfield="false"
                                data-decimal-length="2" data-label="leadname"
                                data-readonly="false" value="">
                        </div>
                        <div class="clearB"></div>
                    </div>
                    <br>
            <button class="btn btn-lg rest-btn-active btn-block" type="submit">Create Lead Status-TEST</button>
                </div>

                <div class="contInfoTab floatR formViewCreate"></div>


            </div>

        </div>
    </div>

</div>
</form>

请问有没有这样的解决方法:

- 示例:

如果{ (帐户)-然后选择 Account.jsp - 在母版页上加载部分视图**(CreateEntity)** } else if (Lead)- 被选中 then Lead.jsp - 在母版页上加载部分视图**(CreateEntity)** }

module可以是controller中的常用方法: 例如,在选定的选项上作为帐户。 URL 看起来像这样:

http://localhost:8080/projectname/CreateEntity?module=Account

http://localhost:8080/projectname/CreateEntity?module=Lead

Please kindly help me regarding this topic.

Thank You!

据我了解你的问题。您的目标是根据您的 URL 参数(模块)包含一个 jsp 页面。为此,您必须将控制器更改为此

***CreateEntityController.java***
  @RequestMapping(value = { "/CreateEntity" }, method = RequestMethod.GET)  
  public ModelAndView CreateEntity(String module,Model model) {  
      model.addAttribute("module", module);  
      model.addAttribute("msg", "This is the partial view page!");
      if(module.equals("Account"){
           //account related attributes
           // call your service or bo and send account related object
           model.addAttribute("account",yourAccountObject)
      }
      if(module.equals("Lead"){
          //lead related attributes
          // call your service or bo and send lead related object
           model.addAttribute("lead",yourLeadObject)
      }
      return new ModelAndView("CreateEntity");
  }

CreateEntity.jsp

 <%-- common code --%>
 <li>
        <a data-params='{"module":"CreateAccountStatus"}' href="<c:url value='CreateEntity?
              module=Account'/>">Create Account </a>
</li>
 <li>
        <a data-params='{"module":"CreateLeadStatus"}' href="<c:url value='CreateEntity?
              module=Lead'/>">Create Account </a>
 </li>

<div>
    <%-- Your partial condition --%>
    <c:choose>
      <c:when test="${module=='Account'}">
         <jsp:include page="Account.jsp" /> 
      </c:when>
       <c:when test="${module=='Lead'}">
         <jsp:include page="Lead.jsp" /> 
      </c:when>
    </c:choose>

</div>