java - java中如何在变量声明中使用特殊字符?

标签 java sql

是否可以使用特殊字符声明java属性名称,例如:

private String var/name;
private int one+one;

我问这个问题是因为我需要从数据库中检索数据,其中一个列的名称是annoces/status,并且我需要使用sql查询(不是hql或criteria)

最佳答案

这是不可能的:

Variable names are case-sensitive. A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_". The convention, however, is to always begin your variable names with a letter, not "$" or "_". Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged. White space is not permitted.

我不明白你为什么需要它。

编辑

您可以使用类似 bbr.sendQuery("Select Status, Name, Annonces/Sta AS annoncesSta, From table ",MyObject.class); 的内容使用AS,您可以更改结果中收到的列的名称。所以你在java类中的属性可以是“annoncesSta”。

无论如何,列名称都带有“/”,名称的最佳实践是:

  • 公告Sta
  • announces_sta

大多数映射器会自动处理这些名称。

关于java - java中如何在变量声明中使用特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13234550/

相关文章:

mysql - 值为NULL时无法添加外键约束?

java - 在 Apache POI 中使用 Excel PERCENTILE 函数

java - 如果在 JVM 关闭过程中再次调用 System.exit() 会发生什么情况?

java - 在继续当前线程之前等待线程完成?

java - 无法在Java中将字符串转换为日期,转换后时区错误

sql - 是否可以在 Sql Server Management Studio Express 中自动缩进查询?

sql - 复合 SQL 连接?

mysql - 对所有列进行编码

sql - 从字符串 oracle 捕获的特殊字符和字符

java - 无法跨类更改 JLabel