File tree 2 files changed +21
-0
lines changed
springboot-starter-data-fast/src/main/java/com/codingapi/springboot/fast/script
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .codingapi .springboot .fast .script ;
2
+
3
+ import jakarta .servlet .http .HttpServletRequest ;
4
+ import lombok .AllArgsConstructor ;
5
+
6
+ @ AllArgsConstructor
7
+ public class ScriptRequest {
8
+
9
+ private final HttpServletRequest request ;
10
+
11
+ public String getParameter (String key , String defaultValue ) {
12
+ String result = request .getParameter (key );
13
+ return result == null ? defaultValue : result ;
14
+ }
15
+
16
+ }
Original file line number Diff line number Diff line change 4
4
import groovy .lang .Binding ;
5
5
import groovy .lang .GroovyShell ;
6
6
import groovy .lang .Script ;
7
+ import org .springframework .web .context .request .RequestContextHolder ;
8
+ import org .springframework .web .context .request .ServletRequestAttributes ;
7
9
8
10
9
11
public class ScriptRuntime {
10
12
11
13
public static Object running (String script , MvcRunningContext context ) {
12
14
Binding binding = new Binding ();
15
+ ServletRequestAttributes attributes = (ServletRequestAttributes ) RequestContextHolder .currentRequestAttributes ();
16
+ ScriptRequest request = new ScriptRequest (attributes .getRequest ());
17
+ binding .setVariable ("$request" , request );
13
18
binding .setVariable ("$jpa" , context .getDynamicQuery ());
14
19
binding .setVariable ("$jdbc" , context .getJdbcQuery ());
15
20
GroovyShell groovyShell = new GroovyShell (binding );
You can’t perform that action at this time.
0 commit comments