简体   繁体   English

如何用Java中的值创建类似类型驱动选择的内容(例如,图片)

[英]How to create something like a type driven selection with values in java (e.g. picture)

If you want to create something like a type driven selection with values : 如果要创建类似类型的带有值的选择:

在此处输入图片说明

What is the best way to save this object-wise in Java (to later persist this with jpa) 在Java中以对象方式保存此对象的最佳方法是什么(以后再用jpa保留它)

I would also like later on to query over this to get eg the avgerage score (what to do with the NA value is also something to think about). 稍后,我还想对此进行查询,以获取平均得分(与NA值有何关系也要考虑)。

No idea how to tackle this, so suggestions would be more then welcome. 不知道如何解决这个问题,因此欢迎提出建议。

If your values are only ever going to be numeric plus N/A, then you can do as Perception and Gavin Xiong suggested and store this as a NUMBER column in the DB. 如果您的值只能是数字加N / A,则可以按照Perception和Gavin Xiong的建议进行操作,并将其存储为数据库中的NUMBER列。 I'd make the column nullable and use DBNULL to represent N/A as Perception suggests, rather than using a magic value (even a "standard" one like -1). 我将使该列可为空,并按照Perception的建议使用DBNULL来表示N / A,而不是使用魔术值(甚至是像-1这样的“标准”值)。 Neither of them addressed how to represent this in the Java code, but I think that null in Java is a more natural mapping to DBNULL in a database in most cases, so I'd represent this as an Integer (Object) rather than an int (primitive) with null == DBNULL == N/A, unless there's a reason to do otherwise. 他们俩都没有解决如何在Java代码中表示这一点,但是我认为Java中的null在大多数情况下是更自然地映射到数据库中的DBNULL,因此我将其表示为Integer(对象)而不是int。 (原始)为null == DBNULL == N / A,除非有其他理由。

You yourself brought up the edge case of how to handle formulas (eg AVERAGE) for N/A values, and you'll need to define your desired behavior in those cases to get a final answer. 您自己提出了如何处理N / A值的公式(例如AVERAGE)的极端情况,并且您需要在这些情况下定义所需的行为以获得最终答案。 Your decision of how to store these value will also make a difference to how complicated your formula queries have to be; 您对如何存储这些值的决定还将使公式查询的复杂程度有所不同。 if you store the value as -1 the way Gavin suggests, you're definitely going to have to write a query with a WHERE clause to exclude those rows from an average value (if that's your desired behavior), whereas you might get some of that for free if you make the column NULLABLE and store DBNULL as the value for N/A. 如果按照Gavin建议的方式将值存储为-1,则肯定要编写一个带有WHERE子句的查询,以将这些行从平均值中排除(如果这是您想要的行为),而您可能会得到一些如果将列设为NULLABLE并将DBNULL存储为N / A的值,则可以免费获得该值。

One note: you should be pretty sure that you're not going to have any non-numeric values other than N/A before you map N/A to DBNULL. 一个注意事项:在将N / A映射到DBNULL之前,您应该非常确定除N / A之外不会有任何非数字值。 If you think there's a good chance there will be other non-numeric values in the future, I'd think seriously about storing this differently, because DBNULL is only ever going to let you represent one non-numeric value. 如果您认为将来很有可能还会有其他非数字值,那么我会认真考虑以不同的方式存储它,因为DBNULL只会让您代表一个非数字值。 If you have to go down that path, I'd store everything as VARCHARs in the DB, and then add code in either Java or SQL/JPA that parse the numeric strings into a number and runs your formula on them dynamically. 如果您必须走这条路,我会将所有内容存储为VARCHAR,然后将其存储在数据库中,然后在Java或SQL / JPA中添加代码,这些代码将数字字符串解析为数字并在其上动态运行公式。 (You could do it with multiple magic values like -1, -2, etc., but it will quickly get kludgy if you have more than a couple of them.) (您可以使用多个魔术值(例如-1,-2等)来执行此操作,但是如果您拥有多个以上魔术值,则会很快变得混乱。)

Why not take it as a radio box and map it into a int property of an object. 为什么不将其作为单选框并将其映射到对象的int属性。 The value range from 0 to 10 and NA can be represented as -1. 取值范围是0到10,NA可以表示为-1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为BitSet类型的元素创建SortedSet(例如TreeSet) - How to create SortedSet (e.g. TreeSet) for elements of type BitSet 如何为Android应用创建标题屏幕? 例如,当应用程序像Facebook一样加载时 - How do you create a title screen for an android app? E.g. When the app is loading like Facebook Java - 如何根据自定义比较最好地执行类似集合的操作(例如retainAll) - Java - how best to perform set-like operations (e.g. retainAll) based on custom comparison Java编译器如何处理类型之外的缺失类型参数 <E> ,例如 <E extends Foo> - How does the java compiler treat missing type arguments for types besides <E>, e.g., <E extends Foo> Java Path 如何转换为例如 InputStream - How is Java Path converted to e.g. InputStream 如何在java中重新绘制特定区域(例如圆圈)? - How to repaint a specific area (e.g. circle) in java? 你如何让java在两个范围内创建一个随机数(例如5-10和12-17) - How do you have java create a random number within two ranges (e.g. 5-10 and 12-17) java.lang.IllegalArgumentException:响应必须包括泛型类型(例如,响应<string> )</string> - java.lang.IllegalArgumentException: Response must include generic type (e.g., Response<String>) 用于泛型类型的Java转换“.class”-operator,例如列表,到“Class <List <?>>”和“Class <List <Integer >>” - Java casting “.class”-operator used on a generic type, e.g. List, to “Class<List<?>>” and to “Class<List<Integer>>” 为什么 Java 类型推断在 int 数组集合的构造函数中失败,例如 PriorityQueue<int[]> ?</int[]> - Why Java type inference fails in constructor for Collection of int array e.g. PriorityQueue<int[]>?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM