Groovy:数据库操作、脚本与类的高效运用
1. 使用数据集(DataSet)
在数据库操作中,Groovy和GSQL能轻松帮助我们创建数据库数据的XML表示。例如,以下代码的XML输出展示了不同城市的温度信息:
<weather>
<city name='Austin' temperature='48' />
<city name='Baton Rouge' temperature='57' />
<city name='Jackson' temperature='50' />
<city name='Montgomery' temperature='53' />
<city name='Phoenix' temperature='67' />
<city name='Sacramento' temperature='66' />
<city name='Santa Fe' temperature='27' />
<city name='Tallahassee' temperature='59' />
</weather>
若想获取过滤后的行集,比如仅获取温度低于33的城市,可通过设置查询条件实现,也可将结果接收为 groovy.sql.DataSet ,它能让我们过滤数据。以下是具体操作步骤:
1. 使用 Sql 类的 dataSet() 方法获取虚拟代理,该方法接收表名,且在迭
超级会员免费看
订阅专栏 解锁全文
117

被折叠的 条评论
为什么被折叠?



