FreeMarker整合
作者:互联网
FreeMarker整合
如何判断空值
1、判断某变量是否存在使用 “??” 用法为:variable??,如果该变量存在,返回true,否则返回false 例:为防止stus为空报错可以加上判断如下
2、缺失变量默认值使用 “!” 使用!要以指定一个默认值,当变量为空时显示默认值。例: ${name!''}表示如果name为空显示空字符串。如果是嵌套对象则建议使用()括起来。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
#empTable{
width: 80%;
border: 1px solid blue;
margin: 0px auto;
}
#empTable,td,th{
border: 1px solid green;
text-align: center;
}
</style>
</head>
<body>
<table id="empTable" cellspacing="0px" cellpadding="0px">
<tr>
<th>索引</th>
<th>工号</th>
<th>姓名</th>
<th>岗位</th>
<th>薪资</th>
<th>补助</th>
<th>部门号</th>
</tr>
<#if emplist ??>
<#list emplist as emp>
<tr <#if emp_index%2==0> style = "background-color: gray"</#if> >
<td>${emp_index}</td>
<td>${emp.empno}</td>
<td>${emp.ename}</td>
<td >${emp.job}</td>
<td<#if emp.sal gte 2000> style = "color: red"</#if>>${emp.sal}</td>
<td>${emp.comm!'0'}</td>
<td>${emp.deptno}</td>
</tr>
</#list>
</#if>
</table>
</body>
</html>
Controller遍历输出指定层
package com.msb.controller;
import com.msb.pojo.Emp;
import com.msb.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class FreemarkerEmpController {
@Autowired
private EmpService empService;
@RequestMapping("/showEmp")
public ModelAndView FindEmplist(){
List<Emp> findemp = empService.findemp();
ModelAndView mv =new ModelAndView();
mv.addObject("emplist",findemp);
mv.setViewName("/showEmp");
return mv;
}
}
标签:FreeMarker,ModelAndView,springframework,mv,emp,整合,org,import 来源: https://www.cnblogs.com/188221creat/p/16419443.html