使用freemark画模板

2019-06-12  本文已影响0人  进击的三文鱼
freemark.png

设定数据过程

@RequestMapping(path = {"/{id}"}, method = {RequestMethod.GET})
    public String queryCustomer(Model model, @PathVariable("id") String id) {
        model.addAttribute("printBody", getPrintBody(id));
        model.addAttribute("source", getPrintItem(id));
        return "ns/ImportManList";
    }
    public List<PrintCrewItem> getPrintItem(String id) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        List<PrintCrewItem> items = Lists.newArrayList();
        SailingSchedule sailingSchedule = sailingScheduleService.findById(id);
        ShDynamic shDynamic = shipDynamicService.findOneBySailingScheduleId(id);
        List<CrewList> crewList = crewListService.findBySailingScheduleIdAndImpExpFlag(sailingSchedule.getId(), "I");
        for (CrewList value : crewList) {
            PrintCrewItem printCrewItem = new PrintCrewItem();
            printCrewItem.setBirthDate(value.getBirthDate());
            printCrewItem.setName(value.getName());
            printCrewItem.setCertificateNo(value.getCertificateNo());
            if (value.getGender() != null) {
                if (value.getGender().equals("M")) {
                    printCrewItem.setGender("男");
                } else if (value.getGender().equals("F")) {
                    printCrewItem.setGender("女");
                } else {
                    printCrewItem.setGender("未知");
                }
            }
            ShipCountry shipCountry = shipCountryService.getByCode(value.getNationality());
            printCrewItem.setCountryName(shipCountry.getCnName());
            printCrewItem.setShipCnName(sailingSchedule.getShipCnName());
            printCrewItem.setVoyageMobile(shDynamic.getVoyageMobile());
            printCrewItem.setAddress(sailingSchedule.getShipCnName());
            printCrewItem.setNowDate(simpleDateFormat.format(new Date()));
            ShipPort shipPort = shipPortService.findByPortCode(sailingSchedule.getLastBerth());
            printCrewItem.setLastBerthName(shipPort.getCnName());
            items.add(printCrewItem);
        }
        return items;
    }
    private ShipPrintBody getPrintBody(String id) {
        SailingSchedule sailingSchedule = sailingScheduleService.findById(id);
        ShipPrintBody printBody = new ShipPrintBody();
        printBody.setShipCnName(sailingSchedule.getShipCnName());
        return printBody;
    }

解决方式td 宽度设定无效

  <td class="tcenter">
              <div style="width: 100px;white-space:normal; word-break:break-all;overflow:hidden;">
                        联系电话
               </div>
   </td>

循环取值

  <#list source as object>
            <tr class="tr_height">
                <td class="tcenter">${object_index+1}</td>
                <td class="tcenter">
                    <div style="width: 70px;white-space:normal; word-break:break-all;overflow:hidden;">
                    ${object.name!}
                    </div>
                </td>
                <td class="tcenter">
                    <div style="width: 20px;white-space:normal; word-break:break-all;overflow:hidden;">
                    ${object.gender!}
                    </div>
                </td>
                <td class="tcenter">${object.birthDate?string("yyyy-MM-dd")!}</td>
                <td class="tcenter">
                    <div style="width: 60px;white-space:normal; word-break:break-all;overflow:hidden;">
                        ${object.countryName!}
                    </div>
                </td>
                <td class="tcenter">
                    <div style="width: 55px;white-space:normal; word-break:break-all;overflow:hidden;">
                    ${object.certificateNo!}
                    </div>
                </td>
                <td class="tcenter ">${object.shipCnName!}</td>
                <td class="tcenter ">
                    <div style="width: 60px;white-space:normal; word-break:break-all;overflow:hidden;">
                    ${object.lastBerthName!}
                    </div>
                </td>
                <td class="tcenter ">
                    <div style="width: 100px;white-space:normal; word-break:break-all;overflow:hidden;">
                    ${object.voyageMobile!}
                    </div>
                </td>
                <td class="tcenter">${object.shipCnName!}</td>
                <td></td>
            </tr>
        </#list>

取值

${printBody.shipCnName!}

格式化日期

${printBody.etdArrivedTime?string("yyyy-MM-dd")!}

if判断

<#if printBody.grossTonnage??>${printBody.grossTonnage?c}</#if>
上一篇 下一篇

猜你喜欢

热点阅读