Home  >  Q&A  >  body text

java - 如何使一张表中的数据相对独立

现有一些表,里面有一些不同公司的的数据,要求当前的操作人只能访问和操作本公司的数据,请问应该怎么实现比较好?
现在用的方法是每个表都加个字段来区分,查询或者操作的时候都加上这个条件。

项目框架 spring mvc +shiro + mybatis + mysql

大家讲道理大家讲道理2766 days ago315

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:04:04

    If there are many companies, you will be fine if you do this.

    There are not many companies, so they can be divided into tables and distinguished by table names. It can also be divided into databases, with one database for each company.

    These three types have their own advantages for tenant types. You can set permissions on the database by table, just like the database, which is more secure. The advantage of the field-by-field method is that it is flexible and does not need to consider the performance impact of cross-table and cross-database operations and the trouble of code writing. But you need to be careful about the permission management of the app. These tasks that could have been done by the database now need to be considered by the app itself.

    reply
    0
  • Cancelreply