java属性文件,为一个属性使用多行

我将sql存储在属性文件中并使用spring注入它,这有效:

someSQL = select result from myTable where y = 2 and x = ? order by z 

但为了便于阅读,我想要这个:

  someSQL = select result from myTable where y = 2 and x = ? order by z 

我需要使用哪种正确的文本格式?

在行尾使用\就像

  someSQL = select result \ from myTable \ where y = 2 \ and x = ? \ order by z 

此外,请注意任何尾随空格,因为Java在组装行时会查找连续反斜杠+换行符。

换句话说:反斜杠必须是换行符之前的最后一个字符。

你添加\(斜杠)继续下一行。 属性文件将是这样的 –

 prop1=first line of prop1 \ second line of prop1\ third line of prop1 prop2=first line of prop2 \n \ second line of prop2 \n \ third line of prop2 

使用\作为新行 ,并确保每个 \ 之前一个空格

  someSQL = select result \ from myTable \ where y = 2 \ and x = ? \ order by z \ 

如果没有给出一个空格,则输出将是这样的

  someSQL = select result\ from myTable\ where y = 2\ and x = ?\ order by z\ someSQL=select resultfrom myTablewhere y = 2and x = ?order by z 

这会导致

Java级别: java.sql.SQLSyntaxErrorException

DB级别 Missing Keyword

实际上, 在’\’之后不要说任何东西都不是一个空白区域 ,这是非常重要的!