Reputation: 217
I have a groovy-servlet named query1_action.groovy as:
String sql = "...";
String sql_count = "...";
try {
def ctx = new javax.naming.InitialContext().lookup("java:/comp/env");
def datasource = ctx.lookup("jdbc/tlink");
def executer = Sql.newInstance(datasource);
def rows = executer.rows(sql);
def gson = new com.google.gson.GsonBuilder().setDateFormat("yyyy-MM-dd").create();
def result = gson.toJson(rows);
def rows_count = executer.firstRow(sql_count).num;
int page_count = (rows_count+page_size-1)/page_size;
out << """{"rs": "1", "rows": ${result}, "rows_count": ${rows_count}, "page": {"page_size": ${page_size}, "page_count": ${page_count}, "pn": ${p.pn}}}""";
} catch(Exception e) {
context.log("query1_action.groovy === ${e}");
out << '{"rs": "0"}';
}
I have query1_action.groovy, query2_action.groovy, and so on, all the try-catch parts are the same.
And I want to make a template-methods by this part.
I do not know how to extends some base class in this case, when I extends class, groovy servlet can not run.
How to make that please?
Upvotes: 1
Views: 35