在哪里保存选择标记的值列表?
我有一个带有选择(下拉)的页面。它将具有如下值:
"SUN" - "Sunday"
"MON" - "Monday"
"TUE" - "Tuesday"
etc.
我可以:
- 将值列表存储在页面(JSP 页面)内 'option' 标签
- 将其保存在 MyForm.class 的 Map 中并将其传递到页面 使用“选项”标签的控制器。
目前的例子是关于一周中的几天(只有7天),但也适用于一个月中的几天(数据量变大)等等。
更好的方法是什么?
PS我正在使用Java、JSP和Spring框架
I have a page with a select (drop-down). It will have values like:
"SUN" - "Sunday"
"MON" - "Monday"
"TUE" - "Tuesday"
etc.
I can:
- store the list of values inside of the page (JSP-page) with
'option' tag - keep it in a Map in MyForm.class and pass it to the page from
Controller using 'options' tag.
The current example is about days of the week(there are only 7 of them), but is also applicable to days of the month (the amount of data becomes bigger), etc.
What will be the better way?
P.S. I'm using Java, JSP and Spring Framework
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这种类型的数据应该通过控制器公开或封装在自定义标签中(或两者兼而有之)。
由于 I18N 问题,您不希望将字符串硬编码到 JSP 中(通常),尽管您可以在 JSP 中为此执行 I18N,但它更加冗长。
This type of data should be exposed through a controller or encapsulated in a custom tag (or both).
You don't want to hard-code strings into a JSP (in general) because of I18N issues, although you could do the I18N for that in the JSP, it's just more verbose.
我建议保留您的类,因为这样您就可以随时更改它,而无需更改 UI。
如果将其保留在 UI 上,则任何更改都将要求您更改 UI 并更改业务类。
I would suggest keeping in your class as that would give you the ability to change it whenever you want without changing the UI.
If you keep it on the UI, any change would require you to change the UI and change the business classes too.