OFBiz进阶--OFBiz标签之[*Services.xml]-mililang介绍与分析(三)

 Mililang标签:  <if/check-*>, 判断操作(Conditional (If) Operations) 

  1. <if>  
  2.   <condition><if-compare operator="less" value="" field="" format="" type="String"></if-compare></condition>  
  3.   <then><return/></then>  
  4.   <else-if>  
  5.     <condition><if-compare operator="less" value="" field="" format="" type="String"></if-compare></condition>  
  6.     <then><return/></then>  
  7.   </else-if>  
  8.   <else><return/></else>  
  9. </if>  
  10.   <!-- 上述标签组合类似 java:if..else..; if 符合条件 then, elseif 符合条件 then, else; -->  
  11.   
  12. <if-compare operator="less" value="" field="" format="" type="String"></if-compare>  
  13.   <!-- field变量的值与 value内容比较 -->  
  14.   <if-compare field="containsEmptyFields" operator="equals" value="true"/>  
  15.   
  16. <if-compare-field operator="less" field="" format="" to-field="" type="String"></if-compare-field>  
  17.   <!-- field变量的值与 to-field变量的值比较 -->  
  18. <if-compare-field field="newEntity.amount" to-field="originalAmount" operator="not-equals" type="BigDecimal">  
  19.     <log level="warning" message="In createFinAccountTrans had to round the amount from [${originalAmount}] to [${newEntity.amount}]"></log>  
  20. </if-compare-field>  
  21.   
  22. <if-empty field=""></if-empty>  
  23.   <!-- 如果 field变量空 -->  
  24.   <if-empty field="currentOrganizationPartyId"></if-empty>  
  25.   
  26. <if-has-permission permission="" action=""></if-has-permission>  
  27.   <!-- 如果当前登录用户有 permission指定模块的 action指定的权限 -->  
  28.   <if-has-permission permission="PAY_INFO" action="_CREATE"/>  
  29.   
  30. <if-instance-of class="" field=""></if-instance-of>  
  31.   <!-- 如果 field变量是 class指定的java类 的类型 -->  
  32. <if-instance-of field="answers[&quot;${currentFieldName}&quot;]" class="java.nio.ByteBuffer">  
  33.     <make-value entity-name="Content" value-field="content"/>  
  34. </if-instance-of>  
  35.   
  36. <if-not-empty field=""></if-not-empty>  
  37.   <!-- 如果 field变量不为空 -->  
  38.   <if-not-empty field="entityValue"></if-not-empty>  
  39.   
  40. <if-regexp field="" expr=""></if-regexp>  
  41.   <!-- 如果 field变量 能匹配 expr 正则表达式  -->  
  42.   <if-regexp field="parameters.partyTaxId" expr="${taxAuthority.taxIdFormatPattern}"/>  
  43.   <if-regexp expr="text.*" field="persistIn.drMimeTypeId" />  
  44.     
  45.   
  46. <if-validate-method field="" method="" class="org.ofbiz.base.util.UtilValidate"></if-validate-method>  
  47.   <!-- 将 field变量传入 class指定的类中的 method指定的方法中校验  -->  
  48.   <if-validate-method field="${answerFieldName}" method="isDate"/>  
  49.   
  50. <check-id field="" error-list-name="error_list"><fail-message message=""/></check-id>  
  51.   <!-- 获取指定变量中的错误消息: field错误消息 -->  
  52.   <check-id field="parameters.fixedAssetId"/>  
  53.   
  54. <check-permission permission="NOTE" action="_${parameters.mainAction}" error-list-name="error_list">  
  55.   <!-- 检查权限: permission权限名; action具体权限值; -->  
  56.   <!-- 使用check-permission前提条件是当前service 环境中必须存在用户的登陆信息,即能获取到userLogin .   
  57.   service 的调用场景有很多,controller.xml中,screen中,simple method 中,bsh文件中,ftl 文件中,java 文件中,groovy文件中等,  
  58.   其中前三项系统会自动将userLogin,locale 等信息自动封装到service context 中去,所以不需要我们手段传值,  
  59.   所以我们在其他环境中调用service的时候就需要对需要的隐性参数进行传值,比如fail-property中会用到locale,   
  60.   check-permission会用到userLogin 等,调用举例如下:   
  61.   dispatcher.runSync("TestServiceOnSimple",UtilMisc.toMap("param3","TestServiceOnJava","userLogin",userLogin,"locale",locale)); //java文件中   
  62.    -->  
  63.   
  64.   <accept-userlogin-party party-id-env-name="partyId"/>  
  65.     <!-- 当前登录用户若无权限, 但操作的数据与当前登录人相关, 则当前登录人也有操作权限, 即校验为true, 如允许用户看到自己的订单,或更新自己的联系人信息。 -->  
  66.     
  67.   <alt-permission permission="" action=""/>   
  68.     <!-- 给当前登录用户分配的备用权限, 若<check-permission>权限校验为false, 继续校验此标签配置权限, 若为true, 则权限校验通过; <alt-permission>可以多个 -->  
  69.     <!-- check-permission 和 alt-permission 两者的关系是or的关系,即只要两者有一个满足权限要求即可。 -->  
  70.     
  71.   <fail-message message=""/>  
  72. !--       <fail-property resource="" property=""/> -->  
  73. </check-permission>  
  74. <check-errors/>  
  75. <!-- <check-permission permission="ACCOUNTING" action="_UPDATE"/> -->  
  76.   
  77. <assert error-list-name="error_list" title="">  
  78.   <!-- 断言:在方法或循环中放置断言, 当断言检查失败时,中断方法的执行,向错误消息列表添加错误消息; error-list-name错误信息列表变量名; title断言的消息 -->  
  79.     
  80.   <and><if-regexp field="" expr=""></if-regexp></and>  
  81.   <not><if-regexp field="" expr=""></if-regexp></not>  
  82.   <or><if-regexp field="" expr=""></if-regexp></or>  
  83.   <xor><if-regexp field="" expr=""></if-regexp></xor>  
  84.     <!-- and/not/or/xor: 并且/非/或者/异或(用于判断数据是否符合条件, 上句是变量是否匹配指定的正则表达式); field变量名; expr正则表达式; -->  
  85. </assert>  
  86.   
  87. <while>  
  88.   <condition><if-compare operator="less" value="" field=""></if-compare></condition>  
  89.   <then></then>  
  90. </while>  
  91.   <!-- while循环: 符合condition中的条件, 则执行 then 中的过程 -->  
  92. <while>  
  93.     <condition>  
  94.         <and>  
  95.             <not><if-empty field="currentOrganizationPartyId"></if-empty></not>  
  96.             <if-compare field="containsEmptyFields" operator="equals" value="true"/>  
  97.         </and>  
  98.     </condition>  
  99.     <then>  
  100.         <clear-field field="parentPartyRelationship"/>  
  101.         <clear-field field="entityKey"/>  
  102.         <clear-field field="entityValue"/>  
  103.     </then>  
  104. </while>  

猜你喜欢

转载自blog.csdn.net/qq_35230695/article/details/79149454