ognl 类
我是在项目中使用Workbook导出excel时使用到了ognl。
如果是jdk1.8
就用ognl3.3.X的版本
<!-- https://mvnrepository.com/artifact/ognl/ognl -->
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>3.3.1</version>
</dependency>
这个版本对应的是jdk8,里面有自带的 MemberAccess 的实现类

如果是jdk7版本
也就是ognl3.3.X以下的版本
就缺少MemberAccess 的实现了,需自己手动补上
官方路径:
https://github.com/orphan-oss/ognl/blob/master/src/test/java/ognl/DefaultMemberAccess.java
复制代码如下:
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 ognl;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Member;
import java.lang.reflect.Modifier;
/**
* This class provides methods for setting up and restoring
* access in a Field. Java 2 provides access utilities for setting
* and getting fields that are non-public. This object provides
* coarse-grained access controls to allow access to private, protected
* and package protected members. This will apply to all classes
* and members.
*/
public class DefaultMemberAccess implements MemberAccess {
/*
* Assign an accessibility modification mechanism, based on Major Java Version.
* Note: Can be overridden using a Java option flag {@link OgnlRuntime#USE_PREJDK9_ACESS_HANDLER}.
*/
private static final AccessibleObjectHandler

在使用OGNL3.3.1版本处理JDK8环境下的Excel导出时,注意到该版本缺少MemberAccess的实现。为了解决这个问题,可以引入官方提供的DefaultMemberAccess类,该类允许对私有、受保护和包访问成员进行访问控制。通过设置allowPrivateAccess、allowProtectedAccess和allowPackageProtectedAccess属性,可以控制不同访问级别的成员访问权限。
9942

被折叠的 条评论
为什么被折叠?



