Skip to content
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

[出现java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888] #1424

Closed
javaHBZ opened this issue Apr 29, 2023 · 14 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@javaHBZ
Copy link

javaHBZ commented Apr 29, 2023

问题描述

在我将对象转化为字符串的时候出现了这个问题,我用其他的工具包转化是没有问题的

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.28]

重现步骤

如何操作可以重现该问题:

  1. 使用 JSON.toJSONString(Object obj) 方法
  2. 输入 数据
  3. 出现 java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888 错误
  public static Object intercept(Invocation invocation) throws Throwable {
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        //请求参数
        Object parameter = null;
        if (1 < invocation.getArgs().length) {
            parameter = invocation.getArgs()[1];
        }
        BoundSql boundSql = mappedStatement.getBoundSql(parameter);
        String sql = boundSql.getSql();
        //执行的sql所在的mapper文件
        String resource = mappedStatement.getResource();
        //执行sql的dao文件的包名+方法名
        String daoMethod = mappedStatement.getId();
        //去除sql文中的换行
        sql = sql.replace("\n", "").replaceAll("\\s+", " ");
        if (SHOWSQL) {
            LOGGER.warn("\n" +
                            "[SQLMonitorPlugin]SQL监控:{}|{}\n" +//方法
                            "执行SQL:\n" +
                            "{}\n" +//SQL
                            "参数:{}", resource, daoMethod,
                    sql, JSON.toJSONString(parameter));
        }
        try {
            long start = System.currentTimeMillis();
            Object e = invocation.proceed();
            long timeTicket = System.currentTimeMillis() - start;
            if (SLOWER < timeTicket) {
                LOGGER.warn("[SQLMonitorInterceptor]SQL监控:{}|{},慢SQL({}/{}ms){},参数:{}",
                        resource, daoMethod, timeTicket, SLOWER, sql, JSON.toJSONString(parameter));
            }
            if (e instanceof Collection) {
                int ct = ((Collection<?>) e).size();
                if (MAXCOUNT < ct) {
                    LOGGER.warn("[SQLMonitorInterceptor]SQL监控:{}|{},大集合({}/{}){},参数:{}",
                            resource, daoMethod, ct, MAXCOUNT, sql, JSON.toJSONString(parameter));
                }
            }
            return e;
        } catch (Exception e) {
            LOGGER.warn("[SQLMonitorPlugin]SQL监控:{}|{},执行出错:{},参数:{}", resource, daoMethod,
                    sql, JSON.toJSONString(parameter), e);
            throw e;
        }
    }

期待的正确结果

成功转化为json字符串

相关日志输出

java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888
at com.alibaba.fastjson2.writer.FieldWriterStringFunc.write(FieldWriterStringFunc.java:41)
at com.alibaba.fastjson2.writer.ObjectWriter1.write(ObjectWriter1.java:68)
at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:373)
at com.alibaba.fastjson2.writer.OWG_2_5_MergeSegments.write(Unknown Source)
at com.alibaba.fastjson2.writer.OWG_1_16_QueryWrapper.write(Unknown Source)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2334)
at org.beite.common.handler.MyBatisSQLMonitorPlugin.intercept(MyBatisSQLMonitorPlugin.java:64)
at org.beite.common.handler.SQLMonitorPlugin.beforeQuery(SQLMonitorPlugin.java:35)
at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy102.query(Unknown Source)
at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:132)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
at com.sun.proxy.$Proxy102.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
at com.sun.proxy.$Proxy80.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy86.selectList(Unknown Source)
at org.beite.service.impl.ArticleTagsServiceImpl.getTagsNames(ArticleTagsServiceImpl.java:57)
at org.beite.service.impl.ArticleTagsServiceImpl$$FastClassBySpringCGLIB$$a9f6dd3a.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386)
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704)
at org.beite.service.impl.ArticleTagsServiceImpl$$EnhancerBySpringCGLIB$$2806e68b.getTagsNames()
at org.beite.service.impl.ArticleServiceImpl.getArticleById(ArticleServiceImpl.java:129)
at org.beite.service.impl.ArticleServiceImpl$$FastClassBySpringCGLIB$$f7fbc213.invoke()
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386)
at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704)
at org.beite.service.impl.ArticleServiceImpl$$EnhancerBySpringCGLIB$$191ae4b6.getArticleById()
at org.beite.controller.article.ArticleController.getArticleById(ArticleController.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.baomidou.mybatisplus.core.conditions.AbstractWrapper$$Lambda$798.831344888
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 89 more

附加信息

image

@javaHBZ javaHBZ added the bug Something isn't working label Apr 29, 2023
@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

这个问题升级到2.0.29应该就好了,你试试看

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

image
image
还是会出现这个问题

@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

AbstractWrapper这个类的代码能提供下么?

@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.30-SNAPSHOT/
问题已经修复,请帮忙用2.0.30-SNAPSHOT版本验证,2.0.30版本预计在5月9日前发布

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

/*

  • Copyright (c) 2011-2020, baomidou ([email protected]).
  • 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
  • https://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.baomidou.mybatisplus.core.conditions;

import com.baomidou.mybatisplus.core.conditions.interfaces.Compare;
import com.baomidou.mybatisplus.core.conditions.interfaces.Func;
import com.baomidou.mybatisplus.core.conditions.interfaces.Join;
import com.baomidou.mybatisplus.core.conditions.interfaces.Nested;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.enums.SqlKeyword;
import com.baomidou.mybatisplus.core.enums.SqlLike;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils;
import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiPredicate;
import java.util.function.Consumer;

import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*;
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY;
import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.BRACKET;
import static java.util.stream.Collectors.joining;

/**

  • 查询条件封装

  • @author hubin miemie HCL

  • @SInCE 2017-05-26
    */
    @SuppressWarnings({"serial", "unchecked"})
    public abstract class AbstractWrapper<T, R, Children extends AbstractWrapper<T, R, Children>> extends Wrapper
    implements Compare<Children, R>, Nested<Children, Children>, Join, Func<Children, R> {

    /**

    • 占位符
      /
      protected final Children typedThis = (Children) this;
      /
      *
    • 必要度量
      /
      protected AtomicInteger paramNameSeq;
      protected Map<String, Object> paramNameValuePairs;
      protected SharedString lastSql;
      /
      *
    • SQL注释
      /
      protected SharedString sqlComment;
      /
      *
    • SQL起始语句
      /
      protected SharedString sqlFirst;
      /
      *
    • ß
    • 数据库表映射实体类
      /
      private T entity;
      protected MergeSegments expression;
      /
      *
    • 实体类型(主要用于确定泛型以及取TableInfo缓存)
      */
      private Class entityClass;

    @OverRide
    public T getEntity() {
    return entity;
    }

    public Children setEntity(T entity) {
    this.entity = entity;
    return typedThis;
    }

    protected Class getEntityClass() {
    if (entityClass == null && entity != null) {
    entityClass = (Class) entity.getClass();
    }
    return entityClass;
    }

    public Children setEntityClass(Class entityClass) {
    if (entityClass != null) {
    this.entityClass = entityClass;
    }
    return typedThis;
    }

    @OverRide
    public Children allEq(boolean condition, Map<R, V> params, boolean null2IsNull) {
    if (condition && CollectionUtils.isNotEmpty(params)) {
    params.forEach((k, v) -> {
    if (StringUtils.checkValNotNull(v)) {
    eq(k, v);
    } else {
    if (null2IsNull) {
    isNull(k);
    }
    }
    });
    }
    return typedThis;
    }

    @OverRide
    public Children allEq(boolean condition, BiPredicate<R, V> filter, Map<R, V> params, boolean null2IsNull) {
    if (condition && CollectionUtils.isNotEmpty(params)) {
    params.forEach((k, v) -> {
    if (filter.test(k, v)) {
    if (StringUtils.checkValNotNull(v)) {
    eq(k, v);
    } else {
    if (null2IsNull) {
    isNull(k);
    }
    }
    }
    });
    }
    return typedThis;
    }

    @OverRide
    public Children eq(boolean condition, R column, Object val) {
    return addCondition(condition, column, EQ, val);
    }

    @OverRide
    public Children ne(boolean condition, R column, Object val) {
    return addCondition(condition, column, NE, val);
    }

    @OverRide
    public Children gt(boolean condition, R column, Object val) {
    return addCondition(condition, column, GT, val);
    }

    @OverRide
    public Children ge(boolean condition, R column, Object val) {
    return addCondition(condition, column, GE, val);
    }

    @OverRide
    public Children lt(boolean condition, R column, Object val) {
    return addCondition(condition, column, LT, val);
    }

    @OverRide
    public Children le(boolean condition, R column, Object val) {
    return addCondition(condition, column, LE, val);
    }

    @OverRide
    public Children like(boolean condition, R column, Object val) {
    return likeValue(condition, column, val, SqlLike.DEFAULT);
    }

    @OverRide
    public Children notLike(boolean condition, R column, Object val) {
    return not(condition).like(condition, column, val);
    }

    @OverRide
    public Children likeLeft(boolean condition, R column, Object val) {
    return likeValue(condition, column, val, SqlLike.LEFT);
    }

    @OverRide
    public Children likeRight(boolean condition, R column, Object val) {
    return likeValue(condition, column, val, SqlLike.RIGHT);
    }

    @OverRide
    public Children between(boolean condition, R column, Object val1, Object val2) {
    return doIt(condition, () -> columnToString(column), BETWEEN, () -> formatSql("{0}", val1), AND,
    () -> formatSql("{0}", val2));
    }

    @OverRide
    public Children notBetween(boolean condition, R column, Object val1, Object val2) {
    return not(condition).between(condition, column, val1, val2);
    }

    @OverRide
    public Children and(boolean condition, Consumer consumer) {
    return and(condition).addNestedCondition(condition, consumer);
    }

    @OverRide
    public Children or(boolean condition, Consumer consumer) {
    return or(condition).addNestedCondition(condition, consumer);
    }

    @OverRide
    public Children nested(boolean condition, Consumer consumer) {
    return addNestedCondition(condition, consumer);
    }

    @OverRide
    public Children or(boolean condition) {
    return doIt(condition, OR);
    }

    @OverRide
    public Children apply(boolean condition, String applySql, Object... value) {
    return doIt(condition, APPLY, () -> formatSql(applySql, value));
    }

    @OverRide
    public Children last(boolean condition, String lastSql) {
    if (condition) {
    this.lastSql.setStringValue(StringPool.SPACE + lastSql);
    }
    return typedThis;
    }

    @OverRide
    public Children comment(boolean condition, String comment) {
    if (condition) {
    this.sqlComment.setStringValue(comment);
    }
    return typedThis;
    }

    @OverRide
    public Children first(boolean condition, String firstSql) {
    if (condition) {
    this.sqlFirst.setStringValue(firstSql);
    }
    return typedThis;
    }

    @OverRide
    public Children exists(boolean condition, String existsSql) {
    return doIt(condition, EXISTS, () -> String.format("(%s)", existsSql));
    }

    @OverRide
    public Children notExists(boolean condition, String notExistsSql) {
    return not(condition).exists(condition, notExistsSql);
    }

    @OverRide
    public Children isNull(boolean condition, R column) {
    return doIt(condition, () -> columnToString(column), IS_NULL);
    }

    @OverRide
    public Children isNotNull(boolean condition, R column) {
    return doIt(condition, () -> columnToString(column), IS_NOT_NULL);
    }

    @OverRide
    public Children in(boolean condition, R column, Collection<?> coll) {
    return doIt(condition, () -> columnToString(column), IN, inExpression(coll));
    }

    @OverRide
    public Children notIn(boolean condition, R column, Collection<?> coll) {
    return not(condition).in(condition, column, coll);
    }

    @OverRide
    public Children inSql(boolean condition, R column, String inValue) {
    return doIt(condition, () -> columnToString(column), IN, () -> String.format("(%s)", inValue));
    }

    @OverRide
    public Children notInSql(boolean condition, R column, String inValue) {
    return not(condition).inSql(condition, column, inValue);
    }

    @OverRide
    public Children groupBy(boolean condition, R... columns) {
    if (ArrayUtils.isEmpty(columns)) {
    return typedThis;
    }
    return doIt(condition, GROUP_BY,
    () -> columns.length == 1 ? columnToString(columns[0]) : columnsToString(columns));
    }

    @OverRide
    public Children orderBy(boolean condition, boolean isAsc, R... columns) {
    if (ArrayUtils.isEmpty(columns)) {
    return typedThis;
    }
    SqlKeyword mode = isAsc ? ASC : DESC;
    for (R column : columns) {
    doIt(condition, ORDER_BY, () -> columnToString(column), mode);
    }
    return typedThis;
    }

    @OverRide
    public Children having(boolean condition, String sqlHaving, Object... params) {
    return doIt(condition, HAVING, () -> formatSqlIfNeed(condition, sqlHaving, params));
    }

    @OverRide
    public Children func(boolean condition, Consumer consumer) {
    if (condition) {
    consumer.accept(typedThis);
    }
    return typedThis;
    }

    /**

    • 内部自用
    • NOT 关键词

    */
    protected Children not(boolean condition) {
    return doIt(condition, NOT);
    }

    /**

    • 内部自用
    • 拼接 AND

    */
    protected Children and(boolean condition) {
    return doIt(condition, AND);
    }

    /**

    • 内部自用
    • 拼接 LIKE 以及 值

    */
    protected Children likeValue(boolean condition, R column, Object val, SqlLike sqlLike) {
    return doIt(condition, () -> columnToString(column), LIKE, () -> formatSql("{0}", SqlUtils.concatLike(val, sqlLike)));
    }

    /**

    • 普通查询条件
    • @param condition 是否执行
    • @param column 属性
    • @param sqlKeyword SQL 关键词
    • @param val 条件值
      */
      protected Children addCondition(boolean condition, R column, SqlKeyword sqlKeyword, Object val) {
      return doIt(condition, () -> columnToString(column), sqlKeyword, () -> formatSql("{0}", val));
      }

    /**

    • 多重嵌套查询条件
    • @param condition 查询条件值
      */
      protected Children addNestedCondition(boolean condition, Consumer consumer) {
      if (condition) {
      final Children instance = instance();
      consumer.accept(instance);
      return doIt(true, BRACKET, instance);
      }
      return typedThis;
      }

    /**

    • 子类返回一个自己的新对象
      */
      protected abstract Children instance();

    /**

    • 格式化SQL
    • @param sqlStr SQL语句部分
    • @param params 参数集
    • @return sql
      */
      protected final String formatSql(String sqlStr, Object... params) {
      return formatSqlIfNeed(true, sqlStr, params);
      }

    /**

    • 根据需要格式化SQL

    • Format SQL for methods: EntityQ.where/and/or...("name={0}", value);
    • ALL the {i} will be replaced with #{MPGENVALi}

    • ew.where("sample_name={0}", "haha").and("sample_age >{0}
    • and sample_age<{1}", 18, 30) TO
    • sample_name=#{MPGENVAL1} and sample_age>#{MPGENVAL2} and
    • sample_age<#{MPGENVAL3}
    • @param need 是否需要格式化
    • @param sqlStr SQL语句部分
    • @param params 参数集
    • @return sql
      */
      protected final String formatSqlIfNeed(boolean need, String sqlStr, Object... params) {
      if (!need || StringUtils.isBlank(sqlStr)) {
      return null;
      }
      if (ArrayUtils.isNotEmpty(params)) {
      for (int i = 0; i < params.length; ++i) {
      String genParamName = Constants.WRAPPER_PARAM + paramNameSeq.incrementAndGet();
      sqlStr = sqlStr.replace(String.format("{%s}", i),
      String.format(Constants.WRAPPER_PARAM_FORMAT, Constants.WRAPPER, genParamName));
      paramNameValuePairs.put(genParamName, params[i]);
      }
      }
      return sqlStr;
      }

    /**

    • 获取in表达式 包含括号
    • @param value 集合
      */
      private ISqlSegment inExpression(Collection<?> value) {
      return () -> value.stream().map(i -> formatSql("{0}", i))
      .collect(joining(StringPool.COMMA, StringPool.LEFT_BRACKET, StringPool.RIGHT_BRACKET));
      }

    /**

    • 必要的初始化
      */
      protected void initNeed() {
      paramNameSeq = new AtomicInteger(0);
      paramNameValuePairs = new HashMap<>(16);
      expression = new MergeSegments();
      lastSql = SharedString.emptyString();
      sqlComment = SharedString.emptyString();
      sqlFirst = SharedString.emptyString();
      }

    @OverRide
    public void clear() {
    entity = null;
    paramNameSeq.set(0);
    paramNameValuePairs.clear();
    expression.clear();
    lastSql.toEmpty();
    sqlComment.toEmpty();
    sqlFirst.toEmpty();
    }

    /**

    • 对sql片段进行组装
    • @param condition 是否执行
    • @param sqlSegments sql片段数组
    • @return children
      */
      protected Children doIt(boolean condition, ISqlSegment... sqlSegments) {
      if (condition) {
      expression.add(sqlSegments);
      }
      return typedThis;
      }

    @OverRide
    public String getSqlSegment() {
    return expression.getSqlSegment() + lastSql.getStringValue();
    }

    @OverRide
    public String getSqlComment() {
    if (StringUtils.isNotBlank(sqlComment.getStringValue())) {
    return "/" + StringEscape.escapeRawString(sqlComment.getStringValue()) + "/";
    }
    return null;
    }

    @OverRide
    public String getSqlFirst() {
    if (StringUtils.isNotBlank(sqlFirst.getStringValue())) {
    return StringEscape.escapeRawString(sqlFirst.getStringValue());
    }
    return null;
    }

    @OverRide
    public MergeSegments getExpression() {
    return expression;
    }

    public Map<String, Object> getParamNameValuePairs() {
    return paramNameValuePairs;
    }

    /**

    • 获取 columnName
      */
      protected String columnToString(R column) {
      return (String) column;
      }

    /**

    • 多字段转换为逗号 "," 分割字符串
    • @param columns 多字段
      */
      protected String columnsToString(R... columns) {
      return Arrays.stream(columns).map(this::columnToString).collect(joining(StringPool.COMMA));
      }

    @OverRide
    @SuppressWarnings("all")
    public Children clone() {
    return SerializationUtils.clone(typedThis);
    }
    }

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

好的 我去试试

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

出现了新的问题,我用的包的名称是 fastjson2-2.0.30-20230429.115149-8.jar

报错信息

 ### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4})'
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at com.sun.proxy.$Proxy80.selectList(Unknown Source) ~[na:na]
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.sun.proxy.$Proxy82.selectList(Unknown Source) ~[na:na]
	at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:370) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:379) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
	at org.beite.service.impl.ArticleCategoryServiceImpl.listAllCategories(ArticleCategoryServiceImpl.java:27) ~[classes/:na]
	at org.beite.service.impl.ArticleCategoryServiceImpl$$FastClassBySpringCGLIB$$f29cc435.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.beite.service.impl.ArticleCategoryServiceImpl$$EnhancerBySpringCGLIB$$648b3ea8.listAllCategories(<generated>) ~[classes/:na]
	at org.beite.controller.article.ArticleCategoryController.getAllCategories(ArticleCategoryController.java:29) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.20.jar:5.3.20]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) [tomcat-embed-core-9.0.63.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.20.jar:5.3.20]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.63.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87) [classes/:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.20.jar:5.3.20]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

是不是没有把rootCause发出来,错误堆栈中没看到fastjson的。没有rootCause的堆栈,不好诊断问题

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'】

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at com.sun.proxy.$Proxy80.selectList(Unknown Source) ~[na:na]
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.sun.proxy.$Proxy86.selectList(Unknown Source) ~[na:na]
	at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:370) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
	at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:379) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
	at org.beite.service.impl.ArticleTagsServiceImpl.listTags(ArticleTagsServiceImpl.java:53) ~[classes/:na]
	at org.beite.service.impl.ArticleTagsServiceImpl$$FastClassBySpringCGLIB$$a9f6dd3a.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.20.jar:5.3.20]
	at org.beite.service.impl.ArticleTagsServiceImpl$$EnhancerBySpringCGLIB$$f7a8bfb.listTags(<generated>) ~[classes/:na]
	at org.beite.controller.article.ArticleTagsController.getListTags(ArticleTagsController.java:30) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.20.jar:5.3.20]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.20.jar:5.3.20]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) [tomcat-embed-core-9.0.63.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.20.jar:5.3.20]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.63.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87) [classes/:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.20.jar:5.3.20]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.20.jar:5.3.20]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.63.jar:9.0.63]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.6.jar:3.5.6]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) ~[mybatis-3.5.6.jar:3.5.6]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.6.jar:3.5.6]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
	... 62 common frames omitted
Caused by: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
	at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2339) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at org.beite.common.handler.MyBatisSQLMonitorPlugin.intercept(MyBatisSQLMonitorPlugin.java:81) ~[classes/:na]
	at org.beite.common.handler.SQLMonitorPlugin.beforeQuery(SQLMonitorPlugin.java:42) ~[classes/:na]
	at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
	at com.sun.proxy.$Proxy102.query(Unknown Source) ~[na:na]
	at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:132) ~[pagehelper-5.3.0.jar:na]
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
	at com.sun.proxy.$Proxy102.query(Unknown Source) ~[na:na]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.6.jar:3.5.6]
	... 68 common frames omitted
Caused by: java.lang.NullPointerException: null
	at com.baomidou.mybatisplus.core.conditions.Wrapper.getTargetSql(Wrapper.java:173) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
	at com.alibaba.fastjson2.writer.FieldWriterStringFunc.write(FieldWriterStringFunc.java:41) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at com.alibaba.fastjson2.writer.ObjectWriterAdapter.write(ObjectWriterAdapter.java:303) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at com.alibaba.fastjson2.writer.FieldWriterObject.write(FieldWriterObject.java:327) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at com.alibaba.fastjson2.writer.ObjectWriter1.write(ObjectWriter1.java:68) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2334) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
	... 77 common frames omitted

@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

加上JSONWriter.Feature.IgnoreErrorGetter试试看,比如:

JSON.toJSONString(object, JSONWriter.Feature.IgnoreErrorGetter);

@wenshao
Copy link
Member

wenshao commented Apr 29, 2023

全局配置:

JSON.config(JSONWriter.Feature.IgnoreErrorGetter);

或者更新下快照,看下新版本是否会不加也不报错

做了这个处理:
8fd9d6d

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

好的

@javaHBZ
Copy link
Author

javaHBZ commented Apr 29, 2023

问题已经解决了,不加也可以,使用的快照版本是 fastjson2-2.0.30-20230429.134008-9.jar

@wenshao wenshao added this to the 2.0.30 milestone Apr 29, 2023
@wenshao wenshao added the fixed label Apr 29, 2023
@wenshao
Copy link
Member

wenshao commented May 6, 2023

@wenshao wenshao closed this as completed May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants