有没有办法转义文本以便在Omnifaces的json表达式中使用: e.g:
declare
sql_stmt varchar2(4000);
rec refcursor;
begin
IF p_trantype='AP'THEN -- Should execute below block
sql_stmt:= 'SELECT al.tax_rate_code AS taxcode,
al.amount AS netamount,
al.amount AS taxamount,
ai.invoice_date AS reportingdate,
ai.invoice_num AS invoicenumber,
ai.invoice_date AS invoicedate,
ai.invoice_amount AS grossamount,
ai.invoice_num AS documentnumber,
ai.invoice_date AS documentdate,
ai.vendor_id AS suplierid,
hz.tax_reference AS suppliervatnumber,
gl.segment1 AS companycode,
'AP' AS transactiontype
from...';
else
sql_stmt:=...
end if;
open rec for sql_stmt;
fetch rec into ...
这似乎是为了逃避单引号,但我想逃避双引号。
答案 0 :(得分:2)
对于EL中的JSON编码,请改用#{of:toJson}
(在OmniFaces 1.5中引入)。
"reviewBody": #{of:toJson(reviewBean.text)}
请注意,它已经处理了双引号。此功能不仅可以处理CharSequence
(String
和朋友),还可以正确处理Number
,Boolean
,Date
,Object[]
, Collection
,Map
甚至是真正的Javabeans。基本上,您可以使用它编码“所有内容”,而无需担心格式和引用。另请参阅showcase,javadoc和source code。