maven导包
<!-- 简体繁体相互转换 --><dependency><groupId>com.spreada</groupId><artifactId>ZHConverter</artifactId><version>1.0.0</version></dependency>
由于我没有导成功,就直接下载的点击下载
/artifact/com.spreada/ZHConverter
下载完成放入项目右键点击Add External Jars
package mon.utils;import com.spreada.utils.chinese.ZHConverter;import java.beans.IntrospectionException;import java.beans.PropertyDescriptor;import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.util.List;/*** 简体繁体相互转换** @author Administrator* @createAuthor: lc* @createDate: /4/14 9:49* @version: 1.0*/public class CHSCHTUtils {/*** 繁体转换简体* @return*/public static String familiarStyle(String traditionalSrc){ZHConverter converter = ZHConverter.getInstance(ZHConverter.SIMPLIFIED);String simplified = converter.convert(traditionalSrc);return simplified;}/*** 简体转换繁体* @param simplified* @return*/public static String complexFont(String simplified){return ZHConverter.convert(simplified,ZHConverter.TRADITIONAL);}/*** 遍历实体将简体字改成繁体字** @createAuthor: lc* @createDate: /4/14 11:54* @version: 1.0*/public static <T> List<T> traversalObject(List<T> list) throws InvocationTargetException, IllegalAccessException, IntrospectionException {for (T obj : list) {Class aClass = obj.getClass();Field[] fields = aClass.getDeclaredFields();for (Field field : fields) {if (field.getType().equals(String.class)) {PropertyDescriptor pd = new PropertyDescriptor(field.getName(),aClass);// 获取get方法Method getMethod = pd.getReadMethod();// 获取set方法Method setMethod = pd.getWriteMethod();// 通过get方法获取到值Object o = getMethod.invoke(obj);if (o != null) {// 更新为新的值setMethod.invoke(obj, complexFont(o.toString()));}}}}return list;}}