Talend中的tJavaRow模块中的(if, else)部分

huangapple go评论75阅读模式
英文:

Talend (if, else) in tJavaRow module

问题

我正在尝试使用tJavaRow模块和条件表达式在一个列中添加信息。目标很简单,如果"Fonction_libelle"列包含"DIRECTEUR"信息,就在"Directeur_Oui_Non"列中添加"Oui",否则添加"Non"。我尝试了以下代码:

if (input_row.Fonction_libelle == "DIRECTEUR") { output_row.Directeur_Oui_Non = "Oui";} else {output_row.Directeur_Oui_Non = "Non";}

但是输出结果是无论如何都是"Non",尽管在"Fonction_libelle"列中有一些"DIRECTEUR"。当然,这里肯定有些问题,但我无法看出是什么问题...

Talend中的tJavaRow模块中的(if, else)部分

非常感谢任何帮助!

英文:

I'm trying to add informations in one column by using tJavaRow module and using conditional expression. The target here is simple. If "Fonction_libelle" column containt "DIRECTEUR" information, add in "Directeur_Oui_Non" column "Oui" else add "Non". I tried this :

if (input_row.Fonction_libelle == "DIRECTEUR") { output_row.Directeur_Oui_Non = "Oui";} else {output_row.Directeur_Oui_Non = "Non";}

The output of this is i've got "Non" everywhere but there are some "DIRECTEUR" in "Fonction_libelle" column. Of course there is something wrong but i'm not able to see what...

Talend中的tJavaRow模块中的(if, else)部分

Any help would be very appreciated !

答案1

得分: 1

请使用.equals()而不是==

if ("DIRECTEUR".equals(input_row.Fonction_libelle)) {
    output_row.Directeur_Oui_Non = "Oui";
} else {
    output_row.Directeur_Oui_Non = "Non";
}

"==" 不推荐用于比较字符串
英文:

Try with .equals() instead of ==

if ("DIRECTEUR".equals(input_row.Fonction_libelle)) {
 output_row.Directeur_Oui_Non = "Oui";}
 else {output_row.Directeur_Oui_Non = "Non";}

"==" is not recommended to compare strings

huangapple
  • 本文由 发表于 2023年7月13日 17:00:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677632.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定