如何用Java编写IF-ELSE语句
我们正在尝试使用eclipse(Talend DI工具)将计算字段作为ship date if then else语句写入java 环境: 我们正试图在塔伦德创造就业机会如何用Java编写IF-ELSE语句,java,excel,eclipse,if-statement,talend,Java,Excel,Eclipse,If Statement,Talend,我们正在尝试使用eclipse(Talend DI工具)将计算字段作为ship date if then else语句写入java 环境: 我们正试图在塔伦德创造就业机会 source systems (sql server and excel file)---->tmap---->Target system(Excel file) 输入表达式:if-then-else公式 发货日期 if ([Customer])='0000001' or (TRIM([Corp Acct Na
source systems (sql server and excel file)---->tmap---->Target system(Excel file)
输入表达式:if-then-else公式
发货日期
if ([Customer])='0000001' or
(TRIM([Corp Acct Name]))='GENERAL' or (TRIM([Corp Acct Name]))='ABC' or (TRIM([Corp Acct Name]))='XYZ'
or (TRIM([Corp Acct Name]))='CDE' then ([ShipDate])
elseif DATEPART('weekday',([MABD])) =1 and [Total Lead Time]<=5 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =1 and [Total Lead Time]>5 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]<=1 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]<=6 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =2 and [Total Lead Time]>6 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]<=2 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]<=7 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =3 and [Total Lead Time]>7 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]<=3 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]<=8 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =4 and [Total Lead Time]>8 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time])
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =5 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time]-1)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-3)
elseif DATEPART('weekday',([MABD])) =6 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-5)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]<=4 then (([MABD])-[Total Lead Time]-2)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]<=9 then (([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])) =7 and [Total Lead Time]>9 then (([MABD])-[Total Lead Time]-6)
END
if([Customer])='0000001'或
(TRIM([公司账户名称])='GENERAL'或(TRIM([公司账户名称])='ABC'或(TRIM([公司账户名称])='XYZ'
或者(TRIM([Corp Acct Name])='CDE',然后([shippdate])
elseif DATEPART('weekday',([MABD])=1和[Total Lead Time]5,然后([MABD])-[Total Lead Time]-4)
elseif DATEPART('weekday',([MABD])=2和[Total Lead Time]首先,表达式中有多个语法错误:如果要比较2 Int,正确的运算符是“==”。
(如果要比较两个字符串,应该使用“0000001”.equals(row1.customer)
)
这个表达式没有意义:
Integer.toString (TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD=1)-1)
如果要将每周的第天与第1天进行比较,请使用
(TalendDate.getPartOfDate("DAY_OF_WEEK",row1.MABD)-1) ==1
然后,在tMap中使用原始三元运算符可能不是最好的做法:它不适合这样一个复杂的表达式(没有可用的注释,没有可能的重用)。相反,您应该在“例程”部分创建一个方法,并将其作为参数row1.customer、row1.CorpAcctName、row1.ShipDate和row1.MABD。
在这个常规方法中,您可以使用IF/ELSE操作符,这是您不能直接在tMap中使用的
public static int myFunction(String customer,String CorpAcctName,Integer ShipDate,Integer MABD) {
//adding comment is possible here
if ("0000001".equals(customer).......) {
然后在tMap中,只需调用表达式构造函数中的函数。如果else
不是表达式,则它是语句。Java没有“例程”,你的意思很可能是一种方法。我会推荐一个入门教程,比如。有没有可能在你的公共函数中添加一行。这对我真的很有帮助。我尝试过与其他人使用公共函数,但按照您的指示执行例程时出错。此处是链接错误消息,类型Calendar中的setTime(Date)不适用于参数(字符串):您应该为param MABD使用日期类型,以便获取TalendDate.getPartofDate()在MABD中提供日期后工作出现以下错误您是否在发布错误消息之前阅读了错误消息?您在方法中使用了java.sql.Date而不是java.util.Date类型。
public static int myFunction(String customer,String CorpAcctName,Integer ShipDate,Integer MABD) {
//adding comment is possible here
if ("0000001".equals(customer).......) {