JSP 在Grails GSP中的运用

来源:互联网 发布:linux连不上网 编辑:程序博客网 时间:2024/05/22 14:37

 其实GSP和Jsp可以户用 在Jsp中直接嵌入Java的代码 会省很多controler回传的事

比如在list 页面里获得run进度的值

 

<%@ page import="java.text.NumberFormat" %> #JSP页面的import都用这种格式

<% #可以直接操作数据库利用findAllBy... 并且可以直接用java类
                                       Integer totalCaseNum=0
                                       TestRun.findById(testRun.id).testCasesForRun.each{
                                            totalCaseNum+=it.subCases.size()+1
                                       }
                                       NumberFormat percentFormat = NumberFormat.getPercentInstance()
                                       Float pass = TestCaseResult.findAllByRunidAndResult(testRun.id,'Pass')?.size()/totalCaseNum
                                       String pass_f = percentFormat.format(pass)
                                       Float fail = TestCaseResult.findAllByRunidAndResult(testRun.id,'Failed')?.size()/totalCaseNum
                                       String fail_f = percentFormat.format(fail)
                                       Float noresult = (totalCaseNum - TestCaseResult.findAllByRunid(testRun.id)?.size())/totalCaseNum
                                       String noresult_f = percentFormat.format(noresult)
 %>

                                  <g:if test="${pass_f!='0%'}"> #对于变量的使用 用<%=params%> 如果pass的比例不为0% 就把pass多少显示
                                  <td width=<%=pass*100%> bgcolor="#66CC66"><font size="1"><%=pass_f%></font></td>
                                  </g:if>

原创粉丝点击