我应该在什么范围内保持 [英] what should I keep in what scope

查看:72
本文介绍了我应该在什么范围内保持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSF 2.0和MySQL创建新网站.以下是我所拥有的.

I am creating new website using JSF 2.0 and MySQL. Below is what I have.

注意在这里,每个表中我仅出于解释目的而考虑1-2个字段.实际上,根据需要,我将有很多字段.

Note Here in each table I am only considering 1-2 fields just for explanation purpose. In real I will have many fields depending on requirement.

我有n个申请人.

ApplicantDataTable
+++++++++++++++++++
 appId     PK
 appName
+++++++++++++++++++

每个申请人都会有很多项目.

Each applicant will have many projects.

ProjectDataTable
+++++++++++++++++++
 proId     PK
 proName
 appId     FK
+++++++++++++++++++

每个项目都会有多个阶段,每个阶段我都需要输入数据.

Each project will have many stages and for each stage I will need to enter data.

stage1datatable
+++++++++++++++++++
 stg001id   PK 
 proId      FK
 stg001name
+++++++++++++++++++

stage2datatable
+++++++++++++++++++
 stg002id   PK 
 proId      FK
 stg002name
+++++++++++++++++++

在申请人屏幕中,我将列出申请人列表.单击此按钮后,我将获得该申请人的项目列表.单击该按钮后,将显示第1阶段屏幕,在第1阶段屏幕中,在底部,我将具有第2、3、4等阶段的链接.

In applicant screen I will have list of applicants. Once I click on this, I will get list of projects of that applicant. Once I click on that, I will have stage 1 screen and in stage 1 screen, at the bottom i will have link for stage 2, 3, 4, etc.

我看到我将不得不接受ProjectId&在所有阶段都使用appId,所以我不确定是否要保留在会话范围内将具有projectId和appId的bean?有人可以建议我如何在Java中构造bean吗?

I see that I will have to take ProjectId & appId through all stages, so I am not sure whether I shall keep bean that will have projectId and appId in session scope? Could some one suggest me how should I structure beans in Java?

任何建议都会很棒.

推荐答案

理想情况下,会话范围适用于您的用例,即将两个ID都存储在会话范围内,但实际上,这可能会过分杀伤力.如果两个ID都将要处理(因此可以在范围中重新存储),则可以将它们保留在

Ideally, the session scope will work for your use case I.e. store both ids in the session scope, but in reality, it might be overkill. If both ids are going to be processed (and hence be available for re-storing in a scope) you could just keep them in the flash scope. On each destination page, you can access those ids and if you will be needing them on the next request, simply re-store them in the same scope. This way, there will be no wastage. Use the putNow() method to guarantee the variables are available after the request has been completed.

与您的问题无关,我不禁注意到您的数据模型中的一些问题

Unrelated to your question I couldn't help but notice a few concerns in your data model

  1. 为什么要在两个表之间复制appName变量?看起来有些不必要的非规范化

  1. Why are you duplicating the appName variable across two tables? Looks like some unnecessary denormalization

为每个项目阶段创建一个表将在不久的将来带来问题.除非您绝对确定项目阶段不会超过2或3,否则我强烈建议您将所有项目阶段合并到一个表中,然后在该表中添加project_stage_id作为字段.结合使用唯一键约束和触发器,以确保不会重复,并且每个项目的项目阶段ID都是连续的(如果需要)

Creating a table for each project stage will bring problems in the near future. Unless you're absolutely certain your project stages will never be more than 2 or 3, I'd strongly recommend you consolidate all your project stages into a single table and then add the project_stage_id as a field in that table. Use a combination of a unique key constraint and a trigger to ensure that duplicates don't occur and that the project stage ids are sequential (if that's a requirement) per project

这篇关于我应该在什么范围内保持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆