标签:FreeMarker ModelAndView springframework mv emp 整合 org import
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
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。