Skip to content

Dev #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jan 2, 2024
Merged

Dev #33

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix PageRequest
  • Loading branch information
xlorne committed Jan 1, 2024
commit 1295ad02dc4797febf0b5306d480a61e8c151121
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.codingapi.springboot.fast.script;

import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;

@AllArgsConstructor
public class ScriptRequest {

private final HttpServletRequest request;

public String getParameter(String key, String defaultValue) {
String result = request.getParameter(key);
return result == null ? defaultValue : result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


public class ScriptRuntime {

public static Object running(String script, MvcRunningContext context) {
Binding binding = new Binding();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
ScriptRequest request = new ScriptRequest(attributes.getRequest());
binding.setVariable("$request", request);
binding.setVariable("$jpa", context.getDynamicQuery());
binding.setVariable("$jdbc", context.getJdbcQuery());
GroovyShell groovyShell = new GroovyShell(binding);
Expand Down