freemaker中前台数据的接收返回处理

时间:2022-01-17 20:31:00

一,前台接收后台数据

接收后台数据时,将后台查到的数据放在data.interns0602中,前台取值如下:

<div class="form-group">
       <label for="followupPeople" class="col-xs-2 col-md-4 control-label text-right "><span style="color:red">*</span>跟进人:</label>
    <div class="col-xs-4 col-md-5">
        <#if data.interns0602Vo ??>
            <input type="text" class="form-control" id="followupPeople" name="followupPeople" maxlength="15" value="${data.interns0602Vo.followupPeople!!}">
          <#else>
            <input type="text" class="form-control" id="followupPeople" name="followupPeople" maxlength="15">
        </#if> 
    </div>
</div>

后台查询数据如下

// 根据id查询信息
Interns0602DetailVo vo = interns0602Dao.initSelect(id);
// 将vo放入map
data.put("interns0602Vo", vo);

 

二,下拉框数据的接收

                    <div class="col-xs-12 col-md-4">
                        <div class="form-group">
                           <label class="control-label text-right col-xs-4">实习项目简称:</label>
                            <div class="col-xs-4">
                                   <select id="projectId" name="projectId" class="form-control selectStyle" data-live-search="true">
                                              <option value="" />
                                       <#if data??>
                                           <#list data.project as project>
                                               <option value="${project.projectId!!}">${project.projectSimname!!}</option>
                                          </#list>
                                       </#if>
                                  </select>
                            </div>
                        </div>
                    </div>

在后台service中将下拉框所需要的值放在data中,前台ftl中value是可以通过id =  "projectId"将数据传到后台去进行处理的;

        // 页面数据编辑
        Map<String, Object> data = new HashMap<String, Object>();
        // 下拉框数据得获得
        List<Interns0401DetailVo> project = interns0401Dao.selectProjectSimname();
        data.put("project", project);
        // 取得结果设定
        resultBean.setResultObject(data);

如果是详情页面,下拉框的初始化值应该为后台闯过来的数据,即当下拉框数据默认初始化为传过来的数据时;

<select id="followupWay" name="followupWay" class="form-control selectStyle" data-live-search="true">
    <#list data.followupWayList as followupWay>
           <#if data.interns0602Vo ?? && data.interns0602Vo.followupWay == followupWay.name>
                    <option  value="${data.interns0602Vo.followupWay!!}" selected>${data.interns0602Vo.followupWay!!}</option>
                <#else>
                    <option  value="${followupWay.name!!}">${followupWay.name!!}</option>
           </#if>
    </#list>
</select> 

后台数据传到页面的数据为

// 根据id查询信息
Interns0602DetailVo vo = interns0602Dao.initSelect(id);
// 将vo放入map
data.put("interns0602Vo", vo);