eclipse开发java使用mybatis打印不带问号的可执行sql
问题
我们开发java的都知道,测试sql的准确行不可少,而使用spring+strust+mybatis框架的不在少数,配置的sql都带问号,并且两三个还好说,你把Preparing+Parameters复制一下弄到数据拼一下,再执行。
下载链接
这是一个SqlUtil.java,看名字就是一个类。放到你项目中即可使用
https://download.youkuaiyun.com/download/xyzz609/10892252
传统步骤5参数大约45秒,20个参数2分钟:
1,复制控制台sql–Preparing到PLSql,美化下sql,并且在最后加分号隔开
select t.org_id orgId,
t.up_org_id upOrgId,
(select h.area_name
from AREA_TM_HZ h
where h.area_type_id = ?
and h.area_id = t.org_id) orgName,
t.index_id indexId,
(select h.index_name from hz_index h where h.index_id = t.index_id) indexName,
t.index_value indexValue,
t.data_level dataLevel,
(select h.end_level from hz_index h where h.index_id = t.index_id) endLevel
from hz_jbxx_day_data t
where 1 = 1
and t.index_id = ?
and t.day_no = ?
and t.data_level = ?
and t.up_org_id = ?
order by to_number(t.index_value) desc;
2,复制控制台sql–Parameters,参数不多,到PLSql
Parameters: 2(String), 101(String), 20190101(String), 2(String), 1(String)
3,没错你需要填参数,这五个参数,加单引号,老手快的给你15秒,这一套下来,粗略算一下40秒,到PLSql,是否可行??????????????
select t.org_id orgId,
t.up_org_id upOrgId,
(select h.area_name
from AREA_TM_HZ h
where h.area_type_id = '2'
and h.area_id = t.org_id) orgName,
t.index_id indexId,
(select h.index_name from hz_index h where h.index_id = t.index_id) indexName,
t.index_value indexValue,
t.data_level dataLevel,
(select h.end_level from hz_index h where h.index_id = t.index_id) endLevel
from hz_jbxx_day_data t
where 1 = 1
and t.index_id = '101'
and t.day_no = '20190101'
and t.data_level = '2'
and t.up_org_id = '1'
order by to_number(t.index_value) desc;
解决三步走,1-20个参数只需8秒:
1,复制控制台sql–Preparing到java工具类
Preparing: select t.org_id orgId, t.up_org_id upOrgId, (select h.area_name from AREA_TM_HZ h where h.area_type_id=? and h.area_id= t.org_id) orgName, t.index_id indexId, (select h.index_name from hz_index h where h.index_id = t.index_id) indexName, t.index_value indexValue, t.data_level dataLevel, (select h.end_level from hz_index h where h.index_id = t.index_id) endLevel from hz_jbxx_day_data t where 1=1 and t.index_id = ? and t.day_no = ? and t.data_level = ? and t.up_org_id = ? order by to_number(t.index_value) desc
2,复制控制台sql–Parameters到java工具类
Parameters: 2(String), 101(String), 20190101(String), 2(String), 1(String)
3,右键执行一下 run as Java Application,直接出拼装sql,复制到PLSql美化执行,总时间不超8秒,除非你电脑卡死了 哈
sql拼装: select t.org_id orgId, t.up_org_id upOrgId, (select h.area_name from AREA_TM_HZ h where h.area_type_id='2' and h.area_id= t.org_id) orgName, t.index_id indexId, (select h.index_name from hz_index h where h.index_id = t.index_id) indexName, t.index_value indexValue, t.data_level dataLevel, (select h.end_level from hz_index h where h.index_id = t.index_id) endLevel from hz_jbxx_day_data t where 1=1 and t.index_id = '101' and t.day_no = '20190101' and t.data_level = '2' and t.up_org_id = '1' order by to_number(t.index_value) desc
下载链接
这是一个SqlUtil.java,看名字就是一个类。放到你项目中即可使用
https://download.youkuaiyun.com/download/xyzz609/10892252