Our application is web-based. Our tools of trade are: Java, JDK1.6, Apache Tomcat v6.0.10, PostgreSQL v8.2.3.
We've a page/screen in the application that has got approx. 20 - 30 checkboxes, which just only denotes yes/no state of the fields.
My question here is, just before I settle down myself on my own design/architecture, I wanted to bounce my implementation with the community and get opinion/advice on how others are looking at/handling this type of design considerations.
My solution/design: Creating a table (USERPREFERENCE) with 3 columns: EMPLOYEEID, FIELDID, STATE. Define/designate each checkbox field by a Unique ID/constant (1, 2, 3, ..., 30). Hence, there would be 20 - 30 entries for each user in this table. Is this normal or is there any different/better way of handling this effectively at the database-level? Also, how do I map the state of 20 - 30 fields (stored row-wise) from database to a JavaBean object automatically, so that it becomes 开发者_开发技巧ease in handling back-and-forth at Java level?
USERPREFERENCE table looks like:
EMPLOYEEID | FIELDID | STATE
100 | 1 | true
100 | 2 | true
100 | 3 | false
... | ... | ...
Any advice/design alternatives are welcome and appreciated.
NOTE: We would also be developing another 4 page/screen with the same functionality having 20 - 30 checkbox fields in each screen.
UPDATE: Please take this into account: The fields are not fixed, new fields may get added in future.
If the fields are of a fixed length and you have a value for each field for most of your entities (EMPLOYEEID
) I would opt for separate boolean
columns for each field. It's more efficient from two points of view:
- storage: you don't have to store a
(EMPLOYEEID, FIELDID)
key for each value (and PostgreSQL is smart about storing booleans) - ease of use: it's easy to query and map the values to your model
精彩评论