Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用多个表的Spring模型_Mysql_Spring_Spring Mvc_Spring Jdbc - Fatal编程技术网

Mysql 使用多个表的Spring模型

Mysql 使用多个表的Spring模型,mysql,spring,spring-mvc,spring-jdbc,Mysql,Spring,Spring Mvc,Spring Jdbc,我得到了一个包含5000多万行的数据库表。通过索引,我将选择单行的请求时间从50秒减少到2-5秒。因为我仍然需要检索多个单行。我甚至可以进一步减少 像上面描述的那样在SQL级别解决它怎么样 在Spring级别,您可以为完整数据表和月视图创建2个dao类 在服务中,请呼叫monthDataDao,如果没有返回任何内容,请使用相同的请求呼叫fullDataDao非常感谢您为我指明了正确的方向。不幸的是,您的代码不是直接的MySQL,或者至少在workbench中不起作用,但我现在有了一个很好的工作基

我得到了一个包含5000多万行的数据库表。通过索引,我将选择单行的请求时间从50秒减少到2-5秒。因为我仍然需要检索多个单行。我甚至可以进一步减少 像上面描述的那样在SQL级别解决它怎么样

在Spring级别,您可以为完整数据表和月视图创建2个dao类


在服务中,请呼叫monthDataDao,如果没有返回任何内容,请使用相同的请求呼叫fullDataDao

非常感谢您为我指明了正确的方向。不幸的是,您的代码不是直接的MySQL,或者至少在workbench中不起作用,但我现在有了一个很好的工作基础。
@Entity
@Table
(
schema="tbl",
name="name_of_view_for_last_month",
fallbackname="name_of_actual_table"
)
select 
  case check.exists
  when 1 then check.id 
  when 0 then (select id 
               from name_of_actual_table
               where <condition to get single row>)
  end as result
from (
    select count(id) as exist, id
    from name_of_view_for_last_month last
    where <condition to get single row>) check