精华内容
下载资源
问答
  • 作者使用框架为ureport2(基于java的spring引擎报表框架)image.pngxmlns:xsi=...

    作者使用的框架为ureport2(基于java的spring引擎的报表框架)

    7236a5153603

    image.png

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

    ">

    可以看到我想修改的类被加入到了spring中管理

    我们先来看看这个类的方法:

    /*******************************************************************************

    * Copyright 2017 Bstek

    *

    * Licensed under the Apache License, Version 2.0 (the "License"); you may not

    * use this file except in compliance with the License. You may obtain a copy

    * of the License at

    *

    * http://www.apache.org/licenses/LICENSE-2.0

    *

    * Unless required by applicable law or agreed to in writing, software

    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

    * License for the specific language governing permissions and limitations under

    * the License.

    ******************************************************************************/

    package com.bstek.ureport.console.designer;

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.PrintWriter;

    import java.util.ArrayList;

    import java.util.Collection;

    import java.util.HashMap;

    import java.util.List;

    import java.util.Map;

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import org.antlr.v4.runtime.ANTLRInputStream;

    import org.antlr.v4.runtime.CommonTokenStream;

    import org.apache.commons.io.IOUtils;

    import org.apache.velocity.Template;

    import org.apache.velocity.VelocityContext;

    import org.springframework.beans.BeansException;

    import org.springframework.context.ApplicationContext;

    import com.bstek.ureport.cache.CacheUtils;

    import com.bstek.ureport.console.RenderPageServletAction;

    import com.bstek.ureport.console.cache.TempObjectCache;

    import com.bstek.ureport.console.exception.ReportDesignException;

    import com.bstek.ureport.definition.ReportDefinition;

    import com.bstek.ureport.dsl.ReportParserLexer;

    import com.bstek.ureport.dsl.ReportParserParser;

    import com.bstek.ureport.dsl.ReportParserParser.DatasetContext;

    import com.bstek.ureport.export.ReportRender;

    import com.bstek.ureport.expression.ErrorInfo;

    import com.bstek.ureport.expression.ScriptErrorListener;

    import com.bstek.ureport.parser.ReportParser;

    import com.bstek.ureport.provider.report.ReportProvider;

    /**

    * @author Jacky.gao

    * @since 2017年1月25日

    */

    public class DesignerServletAction extends RenderPageServletAction {

    private ReportRender reportRender;

    private ReportParser reportParser;

    private List reportProviders=new ArrayList();

    @Override

    public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String method=retriveMethod(req);

    if(method!=null){

    invokeMethod(method, req, resp);

    }else{

    VelocityContext context = new VelocityContext();

    context.put("contextPath", req.getContextPath());

    resp.setContentType("text/html");

    resp.setCharacterEncoding("utf-8");

    Template template=ve.getTemplate("ureport-html/designer.html","utf-8");

    PrintWriter writer=resp.getWriter();

    template.merge(context, writer);

    writer.close();

    }

    }

    public void scriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expression();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void conditionScriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expr();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void parseDatasetName(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String expr=req.getParameter("expr");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(expr);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    parser.removeErrorListeners();

    DatasetContext ctx=parser.dataset();

    String datasetName=ctx.Identifier().getText();

    Map result=new HashMap();

    result.put("datasetName", datasetName);

    writeObjectToJson(resp, result);

    }

    public void savePreviewData(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    content=decodeContent(content);

    InputStream inputStream=IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream,"p");

    reportRender.rebuildReportDefinition(reportDef);

    IOUtils.closeQuietly(inputStream);

    TempObjectCache.putObject(PREVIEW_KEY, reportDef);

    }

    public void loadReport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    file=ReportUtils.decodeFileName(file);

    Object obj=TempObjectCache.getObject(file);

    if(obj!=null && obj instanceof ReportDefinition){

    ReportDefinition reportDef=(ReportDefinition)obj;

    TempObjectCache.removeObject(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }else{

    ReportDefinition reportDef=reportRender.parseReport(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }

    }

    public void deleteReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.deleteReport(file);

    }

    public void saveReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    file=ReportUtils.decodeFileName(file);

    String content=req.getParameter("content");

    content=decodeContent(content);

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.saveReport(file, content);

    InputStream inputStream=IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream, file);

    reportRender.rebuildReportDefinition(reportDef);

    CacheUtils.cacheReportDefinition(file, reportDef);

    IOUtils.closeQuietly(inputStream);

    }

    public void loadReportProviders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    writeObjectToJson(resp, reportProviders);

    }

    public void setReportRender(ReportRender reportRender) {

    this.reportRender = reportRender;

    }

    public void setReportParser(ReportParser reportParser) {

    this.reportParser = reportParser;

    }

    @Override

    public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {

    super.setApplicationContext(applicationContext);

    Collection providers=applicationContext.getBeansOfType(ReportProvider.class).values();

    for(ReportProvider provider:providers){

    if(provider.disabled() || provider.getName()==null){

    continue;

    }

    reportProviders.add(provider);

    }

    }

    @Override

    public String url() {

    return "/designer";

    }

    }

    没错,作者我本人想修改ureport2的loadReport方法,因为框架中的下载文件名一直是ureport-p.xlsx,所以我想修改。

    作者在这里提供2种方法,有一种方法是我工作的老大给的建议

    1:我的思路

    7236a5153603

    image.png

    新建一个类和jar包类的方法一模一样,因为自己的代码的优先级高于maven依赖的版本

    参考网址:https://blog.csdn.net/yw_1207/article/details/80828236

    代码如下:

    package com.sf.energy.nplatform.report.adapter;

    import com.bstek.ureport.cache.CacheUtils;

    import com.bstek.ureport.console.RenderPageServletAction;

    import com.bstek.ureport.console.cache.TempObjectCache;

    import com.bstek.ureport.console.designer.ReportDefinitionWrapper;

    import com.bstek.ureport.console.designer.ReportUtils;

    import com.bstek.ureport.console.exception.ReportDesignException;

    import com.bstek.ureport.definition.ReportDefinition;

    import com.bstek.ureport.dsl.ReportParserLexer;

    import com.bstek.ureport.dsl.ReportParserParser;

    import com.bstek.ureport.export.ReportRender;

    import com.bstek.ureport.expression.ErrorInfo;

    import com.bstek.ureport.expression.ScriptErrorListener;

    import com.bstek.ureport.parser.ReportParser;

    import com.bstek.ureport.provider.report.ReportProvider;

    import org.antlr.v4.runtime.ANTLRInputStream;

    import org.antlr.v4.runtime.CommonTokenStream;

    import org.apache.commons.io.IOUtils;

    import org.apache.velocity.Template;

    import org.apache.velocity.VelocityContext;

    import org.springframework.beans.BeansException;

    import org.springframework.context.ApplicationContext;

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.PrintWriter;

    import java.util.*;

    /**

    * @Author bi xuan

    * @Date 1/27/2021 2:52 PM

    * @Version 1.0

    */

    public class DesignerServletAction extends RenderPageServletAction {

    private ReportRender reportRender;

    private ReportParser reportParser;

    private List reportProviders=new ArrayList();

    private String fileName;

    public String getFileName() {

    return fileName;

    }

    @Override

    public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String method=retriveMethod(req);

    if(method!=null){

    invokeMethod(method, req, resp);

    }else{

    VelocityContext context = new VelocityContext();

    context.put("contextPath", req.getContextPath());

    resp.setContentType("text/html");

    resp.setCharacterEncoding("utf-8");

    Template template=ve.getTemplate("ureport-html/designer.html","utf-8");

    PrintWriter writer=resp.getWriter();

    template.merge(context, writer);

    writer.close();

    }

    }

    public void scriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expression();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void conditionScriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expr();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void parseDatasetName(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String expr=req.getParameter("expr");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(expr);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    parser.removeErrorListeners();

    ReportParserParser.DatasetContext ctx=parser.dataset();

    String datasetName=ctx.Identifier().getText();

    Map result=new HashMap();

    result.put("datasetName", datasetName);

    writeObjectToJson(resp, result);

    }

    public void savePreviewData(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    content=decodeContent(content);

    InputStream inputStream= IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream,"p");

    reportRender.rebuildReportDefinition(reportDef);

    IOUtils.closeQuietly(inputStream);

    TempObjectCache.putObject(PREVIEW_KEY, reportDef);

    }

    public void loadReport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    //备注file不能修改,调试源码时发现这个loadReport被调用了两次,第一次是加载整个报表界面使用,第二次是加载报表列表使用,改了就会报错

    file= ReportUtils.decodeFileName(file);

    this.fileName = file;

    // this.fileName = this.fileName.replace("file:","").split(".")[0];

    this.fileName = this.fileName.replace("file:","").split("\\.")[0];

    Object obj=TempObjectCache.getObject(file);

    if(obj!=null && obj instanceof ReportDefinition){

    ReportDefinition reportDef=(ReportDefinition)obj;

    TempObjectCache.removeObject(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }else{

    ReportDefinition reportDef=reportRender.parseReport(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }

    }

    public void deleteReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.deleteReport(file);

    }

    public void saveReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    file=ReportUtils.decodeFileName(file);

    String content=req.getParameter("content");

    content=decodeContent(content);

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.saveReport(file, content);

    InputStream inputStream=IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream, file);

    reportRender.rebuildReportDefinition(reportDef);

    CacheUtils.cacheReportDefinition(file, reportDef);

    IOUtils.closeQuietly(inputStream);

    }

    public void loadReportProviders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    writeObjectToJson(resp, reportProviders);

    }

    public void setReportRender(ReportRender reportRender) {

    this.reportRender = reportRender;

    }

    public void setReportParser(ReportParser reportParser) {

    this.reportParser = reportParser;

    }

    @Override

    public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {

    super.setApplicationContext(applicationContext);

    Collection providers=applicationContext.getBeansOfType(ReportProvider.class).values();

    for(ReportProvider provider:providers){

    if(provider.disabled() || provider.getName()==null){

    continue;

    }

    reportProviders.add(provider);

    }

    }

    @Override

    public String url() {

    return "/designer";

    }

    }

    然后将其加入到spring管理中,我这里使用的和框架一样的方式,使用xml的bean标签加入到xml中

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

    ">

    修改的代码:

    之前的calss为jar包里类的reference。

    由于jvm的加载优先级问题,就会找bean的id找到我们的类进行实例化加到bean,替代了框架里的类。

    到此我们思路结束了。

    2:我工作老大的思路

    7236a5153603

    image.png

    新建一个adapter类

    代码如下:

    package com.sf.energy.nplatform.report.adapter;

    import com.bstek.ureport.cache.CacheUtils;

    import com.bstek.ureport.console.RenderPageServletAction;

    import com.bstek.ureport.console.cache.TempObjectCache;

    import com.bstek.ureport.console.designer.DesignerServletAction;

    import com.bstek.ureport.console.designer.ReportDefinitionWrapper;

    import com.bstek.ureport.console.designer.ReportUtils;

    import com.bstek.ureport.console.exception.ReportDesignException;

    import com.bstek.ureport.definition.ReportDefinition;

    import com.bstek.ureport.dsl.ReportParserLexer;

    import com.bstek.ureport.dsl.ReportParserParser;

    import com.bstek.ureport.export.ReportRender;

    import com.bstek.ureport.expression.ErrorInfo;

    import com.bstek.ureport.expression.ScriptErrorListener;

    import com.bstek.ureport.parser.ReportParser;

    import com.bstek.ureport.provider.report.ReportProvider;

    import org.antlr.v4.runtime.ANTLRInputStream;

    import org.antlr.v4.runtime.CommonTokenStream;

    import org.apache.commons.io.IOUtils;

    import org.apache.velocity.Template;

    import org.apache.velocity.VelocityContext;

    import org.springframework.beans.BeansException;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.context.ApplicationContext;

    import org.springframework.context.annotation.Bean;

    import org.springframework.stereotype.Component;

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import java.io.IOException;

    import java.io.InputStream;

    import java.io.PrintWriter;

    import java.util.*;

    /**

    * @Author bi xuan

    * @Date 2021/1/13 18:19

    * @Version 1.0

    */

    //@Component

    public class DesignerServletActionAdapter extends RenderPageServletAction {

    // @Autowired

    private ReportRender reportRender;

    // @Autowired

    private ReportParser reportParser;

    private List reportProviders=new ArrayList();

    private String fileName;

    public String getFileName() {

    return fileName;

    }

    @Override

    public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String method=retriveMethod(req);

    if(method!=null){

    invokeMethod(method, req, resp);

    }else{

    VelocityContext context = new VelocityContext();

    context.put("contextPath", req.getContextPath());

    resp.setContentType("text/html");

    resp.setCharacterEncoding("utf-8");

    Template template=ve.getTemplate("ureport-html/designer.html","utf-8");

    PrintWriter writer=resp.getWriter();

    template.merge(context, writer);

    writer.close();

    }

    }

    public void scriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expression();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void conditionScriptValidation(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(content);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    ScriptErrorListener errorListener=new ScriptErrorListener();

    parser.removeErrorListeners();

    parser.addErrorListener(errorListener);

    parser.expr();

    List infos=errorListener.getInfos();

    writeObjectToJson(resp, infos);

    }

    public void parseDatasetName(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String expr=req.getParameter("expr");

    ANTLRInputStream antlrInputStream=new ANTLRInputStream(expr);

    ReportParserLexer lexer=new ReportParserLexer(antlrInputStream);

    CommonTokenStream tokenStream=new CommonTokenStream(lexer);

    ReportParserParser parser=new ReportParserParser(tokenStream);

    parser.removeErrorListeners();

    ReportParserParser.DatasetContext ctx=parser.dataset();

    String datasetName=ctx.Identifier().getText();

    Map result=new HashMap();

    result.put("datasetName", datasetName);

    writeObjectToJson(resp, result);

    }

    public void savePreviewData(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String content=req.getParameter("content");

    content=decodeContent(content);

    InputStream inputStream= IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream,"p");

    reportRender.rebuildReportDefinition(reportDef);

    IOUtils.closeQuietly(inputStream);

    TempObjectCache.putObject(PREVIEW_KEY, reportDef);

    }

    public void loadReport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    //备注file不能修改,调试源码时发现这个loadReport被调用了两次,第一次是加载整个报表界面使用,第二次是加载报表列表使用,改了就会报错

    file= ReportUtils.decodeFileName(file);

    this.fileName = file;

    // this.fileName = this.fileName.replace("file:","").split(".")[0];

    this.fileName = this.fileName.replace("file:","").split("\\.")[0];

    Object obj=TempObjectCache.getObject(file);

    if(obj!=null && obj instanceof ReportDefinition){

    ReportDefinition reportDef=(ReportDefinition)obj;

    TempObjectCache.removeObject(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }else{

    ReportDefinition reportDef=reportRender.parseReport(file);

    writeObjectToJson(resp, new ReportDefinitionWrapper(reportDef));

    }

    }

    public void deleteReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    if(file==null){

    throw new ReportDesignException("Report file can not be null.");

    }

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.deleteReport(file);

    }

    public void saveReportFile(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String file=req.getParameter("file");

    file=ReportUtils.decodeFileName(file);

    String content=req.getParameter("content");

    content=decodeContent(content);

    ReportProvider targetReportProvider=null;

    for(ReportProvider provider:reportProviders){

    if(file.startsWith(provider.getPrefix())){

    targetReportProvider=provider;

    break;

    }

    }

    if(targetReportProvider==null){

    throw new ReportDesignException("File ["+file+"] not found available report provider.");

    }

    targetReportProvider.saveReport(file, content);

    InputStream inputStream=IOUtils.toInputStream(content,"utf-8");

    ReportDefinition reportDef=reportParser.parse(inputStream, file);

    reportRender.rebuildReportDefinition(reportDef);

    CacheUtils.cacheReportDefinition(file, reportDef);

    IOUtils.closeQuietly(inputStream);

    }

    public void loadReportProviders(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    writeObjectToJson(resp, reportProviders);

    }

    public void setReportRender(ReportRender reportRender) {

    this.reportRender = reportRender;

    }

    public void setReportParser(ReportParser reportParser) {

    this.reportParser = reportParser;

    }

    @Override

    public void setApplicationContext(ApplicationContext applicationContext)throws BeansException {

    super.setApplicationContext(applicationContext);

    Collection providers=applicationContext.getBeansOfType(ReportProvider.class).values();

    for(ReportProvider provider:providers){

    if(provider.disabled() || provider.getName()==null){

    continue;

    }

    reportProviders.add(provider);

    }

    }

    @Override

    public String url() {

    return "/designer";

    }

    }

    然后修改自己的xml

    哈哈,你可能发现这不是一模一样吗?

    其实我厚着脸皮承认其实都是我工作老大给的思路,

    接下来是前方高能:作者自己的思路

    因为我才毕业半年,在我接触到Java时就是springboot了,我不喜欢xml文件,所以我要用注解

    7236a5153603

    image.png

    xml注释掉

    7236a5153603

    image.png

    抱着好奇的心态run了一下,可以,这时开始头脑一片问号

    @Autowired注解是根据byType进行加载的

    这明显我的type是DesignerServletActionAdapter,jar包的是DesignServletAction,这类型都不同,是怎么替换的啊!

    我决定查看调用栈一探究竟

    7236a5153603

    image.png

    7236a5153603

    image.png

    7236a5153603

    image.png

    7236a5153603

    image.png

    7236a5153603

    image.png

    没错。他是根据url这个方法来获取类的!(其实这里还是有一个疑惑,因为我重写的类的方法返回的还是/desinger,难到是因为我写的优先级方法高吗?)

    7236a5153603

    image.png

    判断url的源码为:

    /*******************************************************************************

    * Copyright 2017 Bstek

    *

    * Licensed under the Apache License, Version 2.0 (the "License"); you may not

    * use this file except in compliance with the License. You may obtain a copy

    * of the License at

    *

    * http://www.apache.org/licenses/LICENSE-2.0

    *

    * Unless required by applicable law or agreed to in writing, software

    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

    * License for the specific language governing permissions and limitations under

    * the License.

    ******************************************************************************/

    package com.bstek.ureport.console;

    import java.io.IOException;

    import java.io.PrintWriter;

    import java.util.Collection;

    import java.util.HashMap;

    import java.util.Map;

    import javax.servlet.ServletConfig;

    import javax.servlet.ServletException;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.lang.StringUtils;

    import org.springframework.web.context.WebApplicationContext;

    import org.springframework.web.context.support.WebApplicationContextUtils;

    /**

    * @author Jacky.gao

    * @since 2017年1月25日

    */

    public class UReportServlet extends HttpServlet {

    private static final long serialVersionUID = 533049461276487971L;

    public static final String URL = "/ureport";

    private Map actionMap = new HashMap();

    @Override

    public void init(ServletConfig config) throws ServletException {

    super.init(config);

    WebApplicationContext applicationContext = getWebApplicationContext(config);

    Collection handlers = applicationContext.getBeansOfType(ServletAction.class).values();

    for (ServletAction handler : handlers) {

    String url = handler.url();

    if (actionMap.containsKey(url)) {

    throw new RuntimeException("Handler [" + url + "] already exist.");

    }

    actionMap.put(url, handler);

    }

    }

    protected WebApplicationContext getWebApplicationContext(ServletConfig config){

    return WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());

    }

    @Override

    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String path = req.getContextPath() + URL;

    String uri = req.getRequestURI();

    String targetUrl = uri.substring(path.length());

    if (targetUrl.length() < 1) {

    outContent(resp, "Welcome to use ureport,please specify target url.");

    return;

    }

    int slashPos = targetUrl.indexOf("/", 1);

    if (slashPos > -1) {

    targetUrl = targetUrl.substring(0, slashPos);

    }

    ServletAction targetHandler = actionMap.get(targetUrl);

    if (targetHandler == null) {

    outContent(resp, "Handler [" + targetUrl + "] not exist.");

    return;

    }

    RequestHolder.setRequest(req);

    try{

    targetHandler.execute(req, resp);

    }catch(Exception ex){

    resp.setCharacterEncoding("UTF-8");

    PrintWriter pw=resp.getWriter();

    Throwable e=buildRootException(ex);

    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

    String errorMsg = e.getMessage();

    if(StringUtils.isBlank(errorMsg)){

    errorMsg=e.getClass().getName();

    }

    pw.write(errorMsg);

    pw.close();

    throw new ServletException(ex);

    }finally{

    RequestHolder.clean();

    }

    }

    private Throwable buildRootException(Throwable throwable){

    if(throwable.getCause()==null){

    return throwable;

    }

    return buildRootException(throwable.getCause());

    }

    private void outContent(HttpServletResponse resp, String msg) throws IOException {

    resp.setContentType("text/html");

    PrintWriter pw = resp.getWriter();

    pw.write("");

    pw.write("UReport Console");

    pw.write("

    ");

    pw.write(msg);

    pw.write("");

    pw.write("");

    pw.flush();

    pw.close();

    }

    }

    展开全文
  • 开发过程中,我们会引入很多工具...下面将介绍其中一种方法:@ComponentScan过滤不需要注入类@ComponentScan 注解默认会扫描该类所在的包下所有配置类,其中ComponentScan下有两个注解includeFilters和excludeF...

    开发过程中,我们会引入很多工具类,在pom.xml引入,idea中external libraries可以看到引入jar的源码。但是我们要重写jar中的某个方法怎么办呢?下面将介绍其中一种方法:

    @ComponentScan过滤不需要注入的类

    @ComponentScan 注解默认会扫描该类所在的包下所有的配置类,其中ComponentScan下有两个注解includeFilters和excludeFilters

    includeFilters:指定扫描时需要实例化的类型

    excludeFilters:指定扫描时需要过滤的类

    因此我们可以启动类上利用excludeFilters过滤需要重写的类,然后在source里面新建包,就可以重写了

    @ComponentScan(basePackages = {"com.lzy.oa"},

    excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {OperationLogAuditEventRepository.class})})

    basePackages为指明需要扫描的包,excludeFilters指明过滤的类,type是指按哪种类型来过滤,classes则为具体的类。

    说到FilterType,有如下五种类型

    public enum FilterType {

    ANNOTATION,//按照注解方式

    ASSIGNABLE_TYPE,//按照指定类型的方式

    ASPECTJ,//使用ASPECTJ表达式的方式

    REGEX,//利用正则表达式进行指定

    CUSTOM//自己实现TypeFilter接口进行自定义规则

    }

    然后将OperationLogAuditEventRepository类从jar复制出来,就可以在里面进行修改了。

    标签:包中,SpringBoot,FilterType,jar,ComponentScan,过滤,excludeFilters,重写

    来源: https://blog.csdn.net/qq_41937388/article/details/110379491

    展开全文
  • 方法就是,向Jar注入无效代码(不合法,或者根本不是代码字符串)。那么无效代码又怎么能正确运行呢?答案就是,你要保证你代码永远不会执行到那一步。我作一个简单例子说明:我们建立一个项目:packagecom....

    方法就是,向Jar注入无效代码(不合法的,或者根本不是代码的字符串)。

    那么无效的代码又怎么能正确运行呢?

    答案就是,你要保证你的代码永远不会执行到那一步。

    我作一个简单的例子说明:

    我们建立一个项目:

    e162f708a0026a3639041638cf41f319.png

    packagecom.TestJar;

    publicclassMain {

    publicstaticvoidmain(String[] args){

    System.out.println(Info.getMessage());

    }

    }

    packagecom.TestJar;

    publicclassInfo {

    publicstaticString getMessage(){

    return"Hello World!";

    }

    privateclassInvalid{

    }

    }

    很简单,运行结果是 Hello World!

    然后我们将Info类输出Jar

    9a549fb6d7c98ed84865b413bd026d5e.png

    现在项目改成这样:

    6b671f6bbe5e208698d43883021f40c8.png

    运行结果仍然是 Hello World!

    我们用jd-gui反编译看看:

    9d8b9847307a6a50089e2f095ae106c3.png

    反编译看得清清楚楚。

    我们的私有内部类Invalid在程序中是没有用。

    现在,我们向Invalid类注入无效代码。

    注入方法很简单,用WinRar之类的解压软件打开,修改,然后保存就行了

    打开这个Invalid内部类

    3545c13f08ce56e6a595b477d42e8609.png

    我们将图中所选择的字符'd'删除

    f5c132b2aac1d4323d5df6c48ca4bebf.png

    然后保存

    8586f01e350e2d610a4b987d0b075593.png

    刷新一下,程序仍然运行:Hello World!

    5aa206282428f2f937d58b4385d71159.png

    再用jd-gui打开Info.jar

    c8d20db1dc411589a8567f71198a963e.png

    它反编译到那里就出错了。

    注意不能将这个方法运行用Android项目上,Android有另一套规则,它需要把Jar转换成dex的。

    展开全文
  • Java动态代理CGlib Jar包

    2017-12-08 18:16:34
    它被广泛使用在基于代理AOP框架(例如Spring AOP和dynaop)提供方法拦截。Hibernate作为最流行ORM工具也同样使用CGLIB库来代理单端关联(集合懒加载除外,它使用另外一种机制)。EasyMock和jMock作为流行的Java...
  • 比如说在对项目的每个方法的执行时间进行监控的需求的时候,不可能对项目中成千上万的方法一个一个的进行...在引入 javassist 的jar包的时候,尽可能的选择高版本的jar包 <dependency> <groupId>javassi

    比如说在对项目的每个方法的执行时间进行监控的需求的时候,不可能对项目中成千上万的方法一个一个的进行处理,当然如果时间要求很宽松的可以 一个一个的进行添加处理。

    但是使用字节码插桩的方法,可以比较方便的进行需求的实现。

    拦截的时候使用的是 javaagent
    编辑、修改 class 字节码文件的时候使用的是 javassist 技术

    在引入 javassist 的jar包的时候,尽可能的选择高版本的jar包

    <dependency>
        <groupId>javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.12.1.GA</version>
    </dependency>
    

    下面这个是,插桩需要的代码,将该java文件打包成jar包,

    然后在项目启动的时候 添加 -javaagent:yyyy.jar=aaa.bbb.ccc

    java -Dfile.encoding=utf-8 -jar xxxx.jar -javaagent:yyyy.jar=aaa.bbb.ccc

    xxxx.jar     表示项目的jar包

    yyyy.jar     表示插桩的jar包

    aaa.bbb.ccc    要监控的类文件夹,或者类文件

    具体到类文件的话,会打印出类中所有方法的执行时间

    具体到类文件夹的话,会打印出类中所有方法的执行时间+所有类的总执行时间(总时间实在最后才会打印出来)

    /**
     * 监控所有的方法类
     *
     * Create by yang_zzu on 2020/6/14 on 20:35
     */
    public class PublicAgentMain {
    
        //javaagent 入口方法
    
        // 以 arg 为前缀的类才会进行插桩处理 -javaagent:xxx.jar=com.sys.insertPile
        public static void premain(String arg, Instrumentation instrumentation) {
    
            System.out.println("hello agent!!!!!");
    
            final String config = arg;
    
            // 使用 javassist ,在运行时修改 class 字节码,就是 插桩
            final ClassPool pool = new ClassPool();
            pool.appendSystemPath();
    
            instrumentation.addTransformer(new ClassFileTransformer() {
                @Override
                public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    
                    if (className == null || !className.replaceAll("/",".").startsWith(config)) {
                        return null;
                    }
    
                    try {
                        className = className.replaceAll("/", ".");
                        CtClass ctClass = pool.get(className);
                        // 获得类中的所有方法
                        for (CtMethod declaredMethod : ctClass.getDeclaredMethods()) {
                            newMethod(declaredMethod);
                        }
                        return ctClass.toBytecode();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
    
                    return null;
                }
            });
    
    
        }
    
        //复制原有的方法(类似于使用 agent )
        private static CtMethod newMethod(CtMethod oldMethod) {
            CtMethod copy = null;
            try {
                //1. 将方法进行复制
                copy = CtNewMethod.copy(oldMethod, oldMethod.getDeclaringClass(), null);
                //类似于使用动态代理
                copy.setName(oldMethod.getName() + "$agent");
                //类文件中添加 sayHello$agent 方法
                oldMethod.getDeclaringClass().addMethod(copy);
    
                //2. 改变原有的方法,将 原有的 sayHello 方法进行重写操作
                if (oldMethod.getReturnType().equals(CtClass.voidType)) {
                    oldMethod.setBody(String.format(voidSource, oldMethod.getName()));
                } else {
                    oldMethod.setBody(String.format(source, oldMethod.getName()));
                }
            } catch (CannotCompileException | NotFoundException e) {
                e.printStackTrace();
            }
            return copy;
    
        }
    
        /**
         * 参数的封装
         * $$ ======》 arg1, arg2, arg3
         * $1 ======》 arg1
         * $2 ======》 arg2
         * $3 ======》 arg3
         * $args ======》 Object[]
         */
        //有返回值得方法
        final static String source = "{ long begin = System.currentTimeMillis();\n" +
                "        Object result;\n" +
                "        try {\n" +
                "            result = ($w)%s$agent($$);\n" + //s% 将参数传递到下一个方法,然后使用 s% 传递的参数进行替换操作, $w 表示的是在进行return的时候会强制的进行类型转换
                "        } finally {\n" +
                "            long end = System.currentTimeMillis();\n" +
                "            System.out.println(end - begin);\n" +
                "        }\n" +
                "        return ($r) result;}";
    
        //没有返回值的方法
        final static String voidSource = "{long begin = System.currentTimeMillis();\n" +
                "        try {\n" +
                "            %s$agent($$);\n" +
                "        } finally {\n" +
                "            long end = System.currentTimeMillis();\n" +
                "            System.out.println(end - begin);\n" +
                "        }}";
    
    
    }

     监听的类的文件夹

     

    pom 文件夹,打包的配置

    <!-- 需要打包的类的 -->
    <Premain-Class>com.sys.insertPilepublic.PublicAgentMain</Premain-Class>
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.sys.yang</groupId>
        <artifactId>mybatisYang</artifactId>
        <version>1.0-SNAPSHOT</version>
    
    
        <dependencies>
            <dependency>
                <groupId>javassist</groupId>
                <artifactId>javassist</artifactId>
                <version>3.12.1.GA</version>
            </dependency>
    
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.17</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.5.1</version>
            </dependency>
            <dependency>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
                <version>1.2</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>5.1.0.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-jcl</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>5.1.0.RELEASE</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-jcl</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis-spring</artifactId>
                <version>2.0.2</version>
            </dependency>
    
        </dependencies>
    
    
        <build>
    
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <archive>
                            <manifestEntries>
                                <Project-name>${project.name}</Project-name>
                                <Project-version>${project.version}</Project-version>
    <!--                            <Premain-Class>com.coderead.agent.AgentMain</Premain-Class>-->
    <!--                            <Premain-Class>com.sys.insertPilepublic.AgentMain</Premain-Class>-->
                                <!-- 需要打包的类的 -->
                                <Premain-Class>com.sys.insertPilepublic.PublicAgentMain</Premain-Class>
                                <Can-Redefine-Classes>false</Can-Redefine-Classes>
                                <Can-Retransform-Classes>false</Can-Retransform-Classes>
                            </manifestEntries>
                        </archive>
                        <skip>true</skip>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>utf8</encoding>
                    </configuration>
                </plugin>
            </plugins>
    
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
                <resource>
                    <directory>src/test/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    
    
    
    </project>

    UserService.java 文件

    /**
     *
     * 字节码插桩
     * 运行的时候需要附着于其他的jar 包,运行
     * java -jar xxx.jar -javaagent:xxxx.jar
     *
     * Create by yang_zzu on 2020/6/14 on 17:35
     */
    public class UserService {
    
        public void sayHello(String s) throws InterruptedException {
            Thread.sleep(50);
            System.out.println("hello world!!! " + s);
        }
    
    
        public Integer sayHelloReturn(String s, Integer age) throws InterruptedException {
            Thread.sleep(100);
            System.out.println("hello world!!! " + s + "age = " + age);
            return age;
        }
    
        public String sayHelloReturnEvery(String name, Integer age, String phone) throws InterruptedException {
            Thread.sleep(200);
            return (name + " 的年龄是 " + age + " 电话是 " + phone);
        }
    
    
    }

     

    AgentTest.java 测试类

    /**
     * Create by yang_zzu on 2020/6/14 on 17:58
     */
    public class AgentTest {
    
        public static void main(String[] args) {
            UserService userService = new UserService();
    
            UserService2 userService2 = new UserService2();
            try {
                userService.sayHello("你好世界@@@@");
                System.out.println("----------------------------------");
                System.out.println("年龄" + userService.sayHelloReturn("萨瓦迪卡", 18));
                System.out.println("----------------------------------");
                System.out.println(userService.sayHelloReturnEvery("小当家", 13, "110110110"));
    
                System.out.println("+++++++++++++++++++++++++++++++++++");
    
                userService2.sayHello("你好我的朋友!!!!!");
                System.out.println("----------------------------------");
    
                System.out.println(userService2.sayHelloReturn("xiaohua", 21));
                System.out.println("----------------------------------");
                System.out.println(userService2.sayHelloReturnEvery("haha", 10, "120110"));
                System.out.println("----------------------------------");
    
    
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    
        }
    
    }

    项目的结构

    本来是不想粘贴测试类的代码,因为粘上代码看着内容比较长,也没有多大的实际意义。

    https://blog.csdn.net/yang_zzu/article/details/106750330

    这个是另外一个,javaagent 的使用,打印 idea 的所有类文件。这个只是作为学习使用,并没有什么实际性的应用。在破解 idea 的时候应用的就是 javaagent 技术

     

     

    展开全文
  • ① 引入jar包 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; ② 实现三个方法 /** * 拦截没有权限请求 * * @author Frank */ @Component public class AuthInterceptor ...
  • 伪静态URL重写是通过微软公司封装好了一个URL重写组件(UrlReswriter.jar)来实现,导入JAR包,在WEB服务中加载伪静态地址拦截器,客户端以静态地址向服务器发起请求,服务器端的拦截拦截客户端请求,查找XML...
  • 1、今天在和客户联调时发现个问题,就是cas的不拦截失效,所有的方法都被拦截了,原因就是 web.xml配置如下: 如上可以看出,cas拦截了所有的路径,不...如上图,这个是cas-client-3.1.3的jar包的子方法,它这...
  • Spring4AOP 面向切面编程实例之方法拦截实例 一下利用Spring4的最后一个版本Spring4.3.9,实现简单的方法拦截实例。 Eclipse 建立java工程,导入必要的jar包,工程目录如下:
  • Struts2拦截器,需要导相应的jar包及复制Struts.xml文件到src目录下,web.xml进行修改 拦截器 在访问Action时候进行拦截处理,需要继承AbstractInterceptor,重写intercept方法案例一:在访问Action输出一句话(买...
  • java agent 技术 不同于AOP、不需要在原程序中增加或者修改代码,而是单独做一个程序jar,实现对目标程序jar的修改,可以在jvm程序启动前、或者运行时 对类进行拦截、修改类中实现(实际是修改jvm方法区中class...
  • 封面作者:yemoze1314一、问题1.1、环境电脑环境:Windows 10;开发工具:IntelliJ IDEA;数据库环境:Redis 3.2.100JDK环境: Jdk1.8;... 二、解答1.jar包依赖,下面这3个依赖包是切面功能实现...
  • 封面作者:yemoze1314一、问题1.1、环境电脑环境:Windows 10;开发工具:IntelliJ IDEA;数据库环境:Redis 3.2.100JDK环境: Jdk1.8;... 二、解答1.jar包依赖,下面这3个依赖包是切面功能实现...
  • 封面作者:yemoze1314一、问题1.1、环境电脑环境:Windows 10;开发工具:IntelliJ IDEA;数据库环境:Redis 3.2.100JDK环境: Jdk1.8;...二、解答1.jar包依赖,下面这3个依赖包是切面功能实现必...
  • 拦截器 ...引入servlet jar包 <!--servlet--> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2..
  • 一、问题 1.1、环境 电脑环境:Windows 10; 开发工具:IntelliJ IDEA; 数据库环境:Redis 3.2.100 ...1.jar包依赖,下面这3个依赖包是切面功能实现必要条件; <!-- 面向切面 added by Taozhouchuan at 2020-8-3 1
  • 想把shiro进行封装打jar包,方便以后其他项目重复使用,但是shiro方法参数都是封装好,我该怎么办。。。? ``` package com.zns.shiro.config; import at.pollux.thymeleaf.shiro.dialect.ShiroDialect; ...
  • cglib.jar下载

    2018-01-20 21:25:51
    CGLIB原理:动态生成一个要代理类的子类,子类重写要代理的类的所有不是final的方法。在子类中采用方法拦截的技术拦截所有父类方法的调用,顺势织入横切逻辑。它比使用java反射的JDK动态代理要快。 CGLIB底层:使用...
  • 定义拦截的包 定义拦截核心 定义拦截器类 <interceptor name="myInterceptor" class="util.MyInterceptor"></interceptor> 定义拦截值栈空间 <interceptor-ref name="defaultStack"></...
  • // 如果类的包名为"java."开始,则有系统默认加载器加载 try { // 得到系统默认加载cl ClassLoader system = ClassLoader.getSystemClassLoader(); clazz = system.loadClass(name); // 加载名称...
  • JavaAgent Maven 配置案例

    千次阅读 2019-01-28 18:11:26
    javaAgent技术,在运行方法之前运行的拦截器,通过JVM加载class二进制文件时候,利用ASM动态修改加载class字节码文件,在监控方法前后进行统一处理。可以粗略理解为使用字节码方式完成功能切面。常用于监控...
  • nosql_memcached_java client

    2013-04-25 15:08:34
    introduction:在运用中主要通过spring拦截器对某一类方法进行拦截,将这些拦截的方法,首先查询memcached,如果有数据,这一类方法就不会再执行,否则继续执行 1.下载memcached-java-client 的jar包 具体可以参考先关...
  • cglib-3.2.0.jar

    2015-11-11 16:57:42
    它广泛被许多AOP框架使用,例如Spring AOP和dynaop,为他们提供方法的interception(拦截)。最流行OR Mapping工具hibernate也使用CGLIB来代理单端single-ended(多对一和一对一)关联(对集合延迟抓取,是...
  • (2)编写目标方法,使其返回JSON对应对象或集合(不是java类型,可以被js解析后显示给客户) (3)在方法上添加@ResponseBody注解 加入jar包 编写目标方法,使其返回JSON对应对象或集合..
  • 1.新建项目,添加jar包到WEB-INF目录下lib文件夹,并添加到builde path里面 整体目录结构如下 2.新建web.xml,添加struts2核心过滤器,和默认首页 1 <?xml version="1.0" encoding="UTF-8"?> 2 <...
  • Java学习笔记-个人整理

    热门讨论 2012-12-19 09:57:07
    {2.4}父类对象的方法调用}{51}{section.2.4} {2.5}封装}{52}{section.2.5} {2.6}多态}{53}{section.2.6} {2.7}Sample code}{54}{section.2.7} {2.8}框架中移动的小球}{59}{section.2.8} {2.9}抽象与接口}{59}{...
  • 动态代理(CGlib 与连接池案例) Cglib代理:针对类来实现代理,对...我们要使用cglib代理必须引入 cglib的jar包 <dependencies> <!-- https://mvnrepository.com/artifact/cglib/cglib --> ...
  • 找错 ...1.方法执行是否结束,是否有返回值。...2.看看参数值有没有获取到,是否是空值...6.jar包是不是有问题 (如果确认代码没有问题,替换一下jar包试试) 7.无报错,无反应。用try catch 捕获。 1. try {
  • 该案例采用目前最流行、最规范的java ee架构,整个应用分为jpa实体层、eao层、业务逻辑层、mvc层和视图层,各层之间分层清晰,层与层之间以松耦合的方法组织在一起。该案例既提供了ide无关的、基于ant管理的项目源码...

空空如也

空空如也

1 2 3 4 5
收藏数 91
精华内容 36
关键字:

java拦截jar包的方法

java 订阅