如果您对java常用工具类感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于java常用工具类的详细内容,我们还将为您解答从开源项目smartframework项目copy过来
如果您对java 常用工具类感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于java 常用工具类的详细内容,我们还将为您解答从开源项目 smartframework 项目 copy 过来备用的相关问题,并且为您提供关于.a文件编译到.framework中,再将framework导入项目,引用出错、chapter3 怎么添加smart-framework这个项目的依赖、Django-rest-framework 接口实现 rest_framework 中有已经定义好的 工具类 mixins generics viewsets、Eclipse轻松玩转SmartFramework的有价值信息。
本文目录一览:- java 常用工具类(从开源项目 smartframework 项目 copy 过来备用)(java开发中常用的工具类)
- .a文件编译到.framework中,再将framework导入项目,引用出错
- chapter3 怎么添加smart-framework这个项目的依赖
- Django-rest-framework 接口实现 rest_framework 中有已经定义好的 工具类 mixins generics viewsets
- Eclipse轻松玩转SmartFramework
java 常用工具类(从开源项目 smartframework 项目 copy 过来备用)(java开发中常用的工具类)
1. 数组操作工具类
package org.smart4j.framework.util;
import org.apache.commons.lang.ArrayUtils;
/**
* 数组操作工具类
*
* @author huangyong
* @since 1.0
*/
public class ArrayUtil {
/**
* 判断数组是否非空
*/
public static boolean isNotEmpty(Object[] array) {
return !ArrayUtils.isEmpty(array);
}
/**
* 判断数组是否为空
*/
public static boolean isEmpty(Object[] array) {
return ArrayUtils.isEmpty(array);
}
/**
* 连接数组
*/
public static Object[] concat(Object[] array1, Object[] array2) {
return ArrayUtils.addAll(array1, array2);
}
/**
* 判断对象是否在数组中
*/
public static <T> boolean contains(T[] array, T obj) {
return ArrayUtils.contains(array, obj);
}
}
2. 转型操作工具类
package org.smart4j.framework.util;
/**
* 转型操作工具类
*
* @author huangyong
* @since 1.0
*/
public class CastUtil {
/**
* 转为 String 型
*/
public static String castString(Object obj) {
return CastUtil.castString(obj, "");
}
/**
* 转为 String 型(提供默认值)
*/
public static String castString(Object obj, String defaultValue) {
return obj != null ? String.valueOf(obj) : defaultValue;
}
/**
* 转为 double 型
*/
public static double castDouble(Object obj) {
return CastUtil.castDouble(obj, 0);
}
/**
* 转为 double 型(提供默认值)
*/
public static double castDouble(Object obj, double defaultValue) {
double doubleValue = defaultValue;
if (obj != null) {
String strValue = castString(obj);
if (StringUtil.isNotEmpty(strValue)) {
try {
doubleValue = Double.parseDouble(strValue);
} catch (NumberFormatException e) {
doubleValue = defaultValue;
}
}
}
return doubleValue;
}
/**
* 转为 long 型
*/
public static long castLong(Object obj) {
return CastUtil.castLong(obj, 0);
}
/**
* 转为 long 型(提供默认值)
*/
public static long castLong(Object obj, long defaultValue) {
long longValue = defaultValue;
if (obj != null) {
String strValue = castString(obj);
if (StringUtil.isNotEmpty(strValue)) {
try {
longValue = Long.parseLong(strValue);
} catch (NumberFormatException e) {
longValue = defaultValue;
}
}
}
return longValue;
}
/**
* 转为 int 型
*/
public static int castInt(Object obj) {
return CastUtil.castInt(obj, 0);
}
/**
* 转为 int 型(提供默认值)
*/
public static int castInt(Object obj, int defaultValue) {
int intValue = defaultValue;
if (obj != null) {
String strValue = castString(obj);
if (StringUtil.isNotEmpty(strValue)) {
try {
intValue = Integer.parseInt(strValue);
} catch (NumberFormatException e) {
intValue = defaultValue;
}
}
}
return intValue;
}
/**
* 转为 boolean 型
*/
public static boolean castBoolean(Object obj) {
return CastUtil.castBoolean(obj, false);
}
/**
* 转为 boolean 型(提供默认值)
*/
public static boolean castBoolean(Object obj, boolean defaultValue) {
boolean booleanValue = defaultValue;
if (obj != null) {
booleanValue = Boolean.parseBoolean(castString(obj));
}
return booleanValue;
}
/**
* 转为 String[] 型
*/
public static String[] castStringArray(Object[] objArray) {
if (objArray == null) {
objArray = new Object[0];
}
String[] strArray = new String[objArray.length];
if (ArrayUtil.isNotEmpty(objArray)) {
for (int i = 0; i < objArray.length; i++) {
strArray[i] = castString(objArray[i]);
}
}
return strArray;
}
/**
* 转为 double[] 型
*/
public static double[] castDoubleArray(Object[] objArray) {
if (objArray == null) {
objArray = new Object[0];
}
double[] doubleArray = new double[objArray.length];
if (!ArrayUtil.isEmpty(objArray)) {
for (int i = 0; i < objArray.length; i++) {
doubleArray[i] = castDouble(objArray[i]);
}
}
return doubleArray;
}
/**
* 转为 long[] 型
*/
public static long[] castLongArray(Object[] objArray) {
if (objArray == null) {
objArray = new Object[0];
}
long[] longArray = new long[objArray.length];
if (!ArrayUtil.isEmpty(objArray)) {
for (int i = 0; i < objArray.length; i++) {
longArray[i] = castLong(objArray[i]);
}
}
return longArray;
}
/**
* 转为 int[] 型
*/
public static int[] castIntArray(Object[] objArray) {
if (objArray == null) {
objArray = new Object[0];
}
int[] intArray = new int[objArray.length];
if (!ArrayUtil.isEmpty(objArray)) {
for (int i = 0; i < objArray.length; i++) {
intArray[i] = castInt(objArray[i]);
}
}
return intArray;
}
/**
* 转为 boolean[] 型
*/
public static boolean[] castBooleanArray(Object[] objArray) {
if (objArray == null) {
objArray = new Object[0];
}
boolean[] booleanArray = new boolean[objArray.length];
if (!ArrayUtil.isEmpty(objArray)) {
for (int i = 0; i < objArray.length; i++) {
booleanArray[i] = castBoolean(objArray[i]);
}
}
return booleanArray;
}
}
3. 类操作工具类
package org.smart4j.framework.util;
import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 类操作工具类
*
* @author huangyong
* @since 1.0
*/
public class ClassUtil {
private static final Logger logger = LoggerFactory.getLogger(ClassUtil.class);
/**
* 获取类加载器
*/
public static ClassLoader getClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
/**
* 获取类路径
*/
public static String getClassPath() {
String classpath = "";
URL resource = getClassLoader().getResource("");
if (resource != null) {
classpath = resource.getPath();
}
return classpath;
}
/**
* 加载类(将自动初始化)
*/
public static Class<?> loadClass(String className) {
return loadClass(className, true);
}
/**
* 加载类
*/
public static Class<?> loadClass(String className, boolean isInitialized) {
Class<?> cls;
try {
cls = Class.forName(className, isInitialized, getClassLoader());
} catch (ClassNotFoundException e) {
logger.error("加载类出错!", e);
throw new RuntimeException(e);
}
return cls;
}
/**
* 是否为 int 类型(包括 Integer 类型)
*/
public static boolean isInt(Class<?> type) {
return type.equals(int.class) || type.equals(Integer.class);
}
/**
* 是否为 long 类型(包括 Long 类型)
*/
public static boolean isLong(Class<?> type) {
return type.equals(long.class) || type.equals(Long.class);
}
/**
* 是否为 double 类型(包括 Double 类型)
*/
public static boolean isDouble(Class<?> type) {
return type.equals(double.class) || type.equals(Double.class);
}
/**
* 是否为 String 类型
*/
public static boolean isString(Class<?> type) {
return type.equals(String.class);
}
}
4. 编码与解码操作工具类


package org.smart4j.framework.util;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.UUID;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.FrameworkConstant;
/**
* 编码与解码操作工具类
*
* @author huangyong
* @since 1.0
*/
public class CodecUtil {
private static final Logger logger = LoggerFactory.getLogger(CodecUtil.class);
/**
* 将 URL 编码
*/
public static String encodeURL(String str) {
String target;
try {
target = URLEncoder.encode(str, FrameworkConstant.UTF_8);
} catch (Exception e) {
logger.error("编码出错!", e);
throw new RuntimeException(e);
}
return target;
}
/**
* 将 URL 解码
*/
public static String decodeURL(String str) {
String target;
try {
target = URLDecoder.decode(str, FrameworkConstant.UTF_8);
} catch (Exception e) {
logger.error("解码出错!", e);
throw new RuntimeException(e);
}
return target;
}
/**
* 将字符串 Base64 编码
*/
public static String encodeBASE64(String str) {
String target;
try {
target = Base64.encodeBase64URLSafeString(str.getBytes(FrameworkConstant.UTF_8));
} catch (UnsupportedEncodingException e) {
logger.error("编码出错!", e);
throw new RuntimeException(e);
}
return target;
}
/**
* 将字符串 Base64 解码
*/
public static String decodeBASE64(String str) {
String target;
try {
target = new String(Base64.decodeBase64(str), FrameworkConstant.UTF_8);
} catch (UnsupportedEncodingException e) {
logger.error("解码出错!", e);
throw new RuntimeException(e);
}
return target;
}
/**
* 将字符串 MD5 加密
*/
public static String encryptMD5(String str) {
return DigestUtils.md5Hex(str);
}
/**
* 将字符串 SHA 加密
*/
public static String encryptSHA(String str) {
return DigestUtils.sha1Hex(str);
}
/**
* 创建随机数
*/
public static String createRandom(int count) {
return RandomStringUtils.randomNumeric(count);
}
/**
* 获取 UUID(32位)
*/
public static String createUUID() {
return UUID.randomUUID().toString().replaceAll("-", "");
}
}
5. 集合操作工具类


package org.smart4j.framework.util;
import java.util.Collection;
import org.apache.commons.collections.CollectionUtils;
/**
* 集合操作工具类
*
* @author huangyong
* @since 1.0
*/
public class CollectionUtil {
/**
* 判断集合是否非空
*/
public static boolean isNotEmpty(Collection<?> collection) {
return CollectionUtils.isNotEmpty(collection);
}
/**
* 判断集合是否为空
*/
public static boolean isEmpty(Collection<?> collection) {
return CollectionUtils.isEmpty(collection);
}
}
6. 日期操作工具类
package org.smart4j.framework.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 日期操作工具类
*
* @author huangyong
* @since 1.0
*/
public class DateUtil {
private static final Logger logger = LoggerFactory.getLogger(DateUtil.class);
private static final SimpleDateFormat datetimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
private static final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
/**
* 格式化日期与时间
*/
public static String formatDatetime(long timestamp) {
return datetimeFormat.format(new Date(timestamp));
}
/**
* 格式化日期
*/
public static String formatDate(long timestamp) {
return dateFormat.format(new Date(timestamp));
}
/**
* 格式化时间
*/
public static String formatTime(long timestamp) {
return timeFormat.format(new Date(timestamp));
}
/**
* 获取当前日期与时间
*/
public static String getCurrentDatetime() {
return datetimeFormat.format(new Date());
}
/**
* 获取当前日期
*/
public static String getCurrentDate() {
return dateFormat.format(new Date());
}
/**
* 获取当前时间
*/
public static String getCurrentTime() {
return timeFormat.format(new Date());
}
/**
* 解析日期与时间
*/
public static Date parseDatetime(String str) {
Date date = null;
try {
date = datetimeFormat.parse(str);
} catch (ParseException e) {
logger.error("解析日期字符串出错!格式:yyyy-MM-dd HH:mm:ss", e);
}
return date;
}
/**
* 解析日期
*/
public static Date parseDate(String str) {
Date date = null;
try {
date = dateFormat.parse(str);
} catch (ParseException e) {
logger.error("解析日期字符串出错!格式:yyyy-MM-dd", e);
}
return date;
}
/**
* 解析时间
*/
public static Date parseTime(String str) {
Date date = null;
try {
date = timeFormat.parse(str);
} catch (ParseException e) {
logger.error("解析日期字符串出错!格式:HH:mm:ss", e);
}
return date;
}
}
7. 文件操作工具类
package org.smart4j.framework.util;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.FrameworkConstant;
/**
* 文件操作工具类
*
* @author huangyong
* @since 1.0
*/
public class FileUtil {
private static final Logger logger = LoggerFactory.getLogger(FileUtil.class);
/**
* 创建目录
*/
public static File createDir(String dirPath) {
File dir;
try {
dir = new File(dirPath);
if (!dir.exists()) {
FileUtils.forceMkdir(dir);
}
} catch (Exception e) {
logger.error("创建目录出错!", e);
throw new RuntimeException(e);
}
return dir;
}
/**
* 创建文件
*/
public static File createFile(String filePath) {
File file;
try {
file = new File(filePath);
File parentDir = file.getParentFile();
if (!parentDir.exists()) {
FileUtils.forceMkdir(parentDir);
}
} catch (Exception e) {
logger.error("创建文件出错!", e);
throw new RuntimeException(e);
}
return file;
}
/**
* 复制目录(不会复制空目录)
*/
public static void copyDir(String srcPath, String destPath) {
try {
File srcDir = new File(srcPath);
File destDir = new File(destPath);
if (srcDir.exists() && srcDir.isDirectory()) {
FileUtils.copyDirectoryToDirectory(srcDir, destDir);
}
} catch (Exception e) {
logger.error("复制目录出错!", e);
throw new RuntimeException(e);
}
}
/**
* 复制文件
*/
public static void copyFile(String srcPath, String destPath) {
try {
File srcFile = new File(srcPath);
File destDir = new File(destPath);
if (srcFile.exists() && srcFile.isFile()) {
FileUtils.copyFileToDirectory(srcFile, destDir);
}
} catch (Exception e) {
logger.error("复制文件出错!", e);
throw new RuntimeException(e);
}
}
/**
* 删除目录
*/
public static void deleteDir(String dirPath) {
try {
File dir = new File(dirPath);
if (dir.exists() && dir.isDirectory()) {
FileUtils.deleteDirectory(dir);
}
} catch (Exception e) {
logger.error("删除目录出错!", e);
throw new RuntimeException(e);
}
}
/**
* 删除文件
*/
public static void deleteFile(String filePath) {
try {
File file = new File(filePath);
if (file.exists() && file.isFile()) {
FileUtils.forceDelete(file);
}
} catch (Exception e) {
logger.error("删除文件出错!", e);
throw new RuntimeException(e);
}
}
/**
* 重命名文件
*/
public static void renameFile(String srcPath, String destPath) {
File srcFile = new File(srcPath);
if (srcFile.exists()) {
File newFile = new File(destPath);
boolean result = srcFile.renameTo(newFile);
if (!result) {
throw new RuntimeException("重命名文件出错!" + newFile);
}
}
}
/**
* 将字符串写入文件
*/
public static void writeFile(String filePath, String fileContent) {
OutputStream os = null;
Writer w = null;
try {
FileUtil.createFile(filePath);
os = new BufferedOutputStream(new FileOutputStream(filePath));
w = new OutputStreamWriter(os, FrameworkConstant.UTF_8);
w.write(fileContent);
w.flush();
} catch (Exception e) {
logger.error("写入文件出错!", e);
throw new RuntimeException(e);
} finally {
try {
if (os != null) {
os.close();
}
if (w != null) {
w.close();
}
} catch (Exception e) {
logger.error("释放资源出错!", e);
}
}
}
/**
* 获取真实文件名(去掉文件路径)
*/
public static String getRealFileName(String fileName) {
return FilenameUtils.getName(fileName);
}
/**
* 判断文件是否存在
*/
public static boolean checkFileExists(String filePath) {
return new File(filePath).exists();
}
}
8. JSON 操作工具类


package org.smart4j.framework.util;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* JSON 操作工具类
*
* @author huangyong
* @since 1.0
*/
public class JsonUtil {
private static final Logger logger = LoggerFactory.getLogger(JsonUtil.class);
private static final ObjectMapper objectMapper = new ObjectMapper();
/**
* 将 Java 对象转为 JSON 字符串
*/
public static <T> String toJSON(T obj) {
String jsonStr;
try {
jsonStr = objectMapper.writeValueAsString(obj);
} catch (Exception e) {
logger.error("Java 转 JSON 出错!", e);
throw new RuntimeException(e);
}
return jsonStr;
}
/**
* 将 JSON 字符串转为 Java 对象
*/
public static <T> T fromJSON(String json, Class<T> type) {
T obj;
try {
obj = objectMapper.readValue(json, type);
} catch (Exception e) {
logger.error("JSON 转 Java 出错!", e);
throw new RuntimeException(e);
}
return obj;
}
}
9. 映射操作工具类


package org.smart4j.framework.util;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
/**
* 映射操作工具类
*
* @author huangyong
* @since 1.0
*/
public class MapUtil {
/**
* 判断 Map 是否非空
*/
public static boolean isNotEmpty(Map<?, ?> map) {
return MapUtils.isNotEmpty(map);
}
/**
* 判断 Map 是否为空
*/
public static boolean isEmpty(Map<?, ?> map) {
return MapUtils.isEmpty(map);
}
/**
* 转置 Map
*/
public static <K, V> Map<V, K> invert(Map<K, V> source) {
Map<V, K> target = null;
if (isNotEmpty(source)) {
target = new LinkedHashMap<V, K>(source.size());
for (Map.Entry<K, V> entry : source.entrySet()) {
target.put(entry.getValue(), entry.getKey());
}
}
return target;
}
}
10. 对象操作工具类


package org.smart4j.framework.util;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 对象操作工具类
*
* @author huangyong
* @since 1.0
*/
public class ObjectUtil {
private static final Logger logger = LoggerFactory.getLogger(ObjectUtil.class);
/**
* 设置成员变量
*/
public static void setField(Object obj, String fieldName, Object fieldValue) {
try {
if (PropertyUtils.isWriteable(obj, fieldName)) {
PropertyUtils.setProperty(obj, fieldName, fieldValue);
}
} catch (Exception e) {
logger.error("设置成员变量出错!", e);
throw new RuntimeException(e);
}
}
/**
* 获取成员变量
*/
public static Object getFieldValue(Object obj, String fieldName) {
Object propertyValue = null;
try {
if (PropertyUtils.isReadable(obj, fieldName)) {
propertyValue = PropertyUtils.getProperty(obj, fieldName);
}
} catch (Exception e) {
logger.error("获取成员变量出错!", e);
throw new RuntimeException(e);
}
return propertyValue;
}
/**
* 复制所有成员变量
*/
public static void copyFields(Object source, Object target) {
try {
for (Field field : source.getClass().getDeclaredFields()) {
// 若不为 static 成员变量,则进行复制操作
if (!Modifier.isStatic(field.getModifiers())) {
field.setAccessible(true); // 可操作私有成员变量
field.set(target, field.get(source));
}
}
} catch (Exception e) {
logger.error("复制成员变量出错!", e);
throw new RuntimeException(e);
}
}
/**
* 通过反射创建实例
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(String className) {
T instance;
try {
Class<?> commandClass = ClassUtil.loadClass(className);
instance = (T) commandClass.newInstance();
} catch (Exception e) {
logger.error("创建实例出错!", e);
throw new RuntimeException(e);
}
return instance;
}
/**
* 获取对象的字段映射(字段名 => 字段值),忽略 static 字段
*/
public static Map<String, Object> getFieldMap(Object obj) {
return getFieldMap(obj, true);
}
/**
* 获取对象的字段映射(字段名 => 字段值)
*/
public static Map<String, Object> getFieldMap(Object obj, boolean isStaticIgnored) {
Map<String, Object> fieldMap = new LinkedHashMap<String, Object>();
Field[] fields = obj.getClass().getDeclaredFields();
for (Field field : fields) {
if (isStaticIgnored && Modifier.isStatic(field.getModifiers())) {
continue;
}
String fieldName = field.getName();
Object fieldValue = ObjectUtil.getFieldValue(obj, fieldName);
fieldMap.put(fieldName, fieldValue);
}
return fieldMap;
}
}
11. 属性文件操作工具类


package org.smart4j.framework.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 属性文件操作工具类
*
* @author huangyong
* @since 1.0
*/
public class PropsUtil {
private static final Logger logger = LoggerFactory.getLogger(PropsUtil.class);
/**
* 加载属性文件
*/
public static Properties loadProps(String propsPath) {
Properties props = new Properties();
InputStream is = null;
try {
if (StringUtil.isEmpty(propsPath)) {
throw new IllegalArgumentException();
}
String suffix = ".properties";
if (propsPath.lastIndexOf(suffix) == -1) {
propsPath += suffix;
}
is = ClassUtil.getClassLoader().getResourceAsStream(propsPath);
if (is != null) {
props.load(is);
}
} catch (Exception e) {
logger.error("加载属性文件出错!", e);
throw new RuntimeException(e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
logger.error("释放资源出错!", e);
}
}
return props;
}
/**
* 加载属性文件,并转为 Map
*/
public static Map<String, String> loadPropsToMap(String propsPath) {
Map<String, String> map = new HashMap<String, String>();
Properties props = loadProps(propsPath);
for (String key : props.stringPropertyNames()) {
map.put(key, props.getProperty(key));
}
return map;
}
/**
* 获取字符型属性
*/
public static String getString(Properties props, String key) {
String value = "";
if (props.containsKey(key)) {
value = props.getProperty(key);
}
return value;
}
/**
* 获取字符型属性(带有默认值)
*/
public static String getString(Properties props, String key, String defalutValue) {
String value = defalutValue;
if (props.containsKey(key)) {
value = props.getProperty(key);
}
return value;
}
/**
* 获取数值型属性
*/
public static int getNumber(Properties props, String key) {
int value = 0;
if (props.containsKey(key)) {
value = CastUtil.castInt(props.getProperty(key));
}
return value;
}
// 获取数值型属性(带有默认值)
public static int getNumber(Properties props, String key, int defaultValue) {
int value = defaultValue;
if (props.containsKey(key)) {
value = CastUtil.castInt(props.getProperty(key));
}
return value;
}
/**
* 获取布尔型属性
*/
public static boolean getBoolean(Properties props, String key) {
return getBoolean(props, key, false);
}
/**
* 获取布尔型属性(带有默认值)
*/
public static boolean getBoolean(Properties props, String key, boolean defalutValue) {
boolean value = defalutValue;
if (props.containsKey(key)) {
value = CastUtil.castBoolean(props.getProperty(key));
}
return value;
}
/**
* 获取指定前缀的相关属性
*/
public static Map<String, Object> getMap(Properties props, String prefix) {
Map<String, Object> kvMap = new LinkedHashMap<String, Object>();
Set<String> keySet = props.stringPropertyNames();
if (CollectionUtil.isNotEmpty(keySet)) {
for (String key : keySet) {
if (key.startsWith(prefix)) {
String value = props.getProperty(key);
kvMap.put(key, value);
}
}
}
return kvMap;
}
}
12. 流操作工具类


package org.smart4j.framework.util;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 流操作工具类
*
* @author huangyong
* @since 1.0
*/
public class StreamUtil {
private static final Logger logger = LoggerFactory.getLogger(StreamUtil.class);
/**
* 将输入流复制到输出流
*/
public static void copyStream(InputStream inputStream, OutputStream outputStream) {
try {
int length;
byte[] buffer = new byte[4 * 1024];
while ((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
outputStream.write(buffer, 0, length);
}
outputStream.flush();
} catch (Exception e) {
logger.error("复制流出错!", e);
throw new RuntimeException(e);
} finally {
try {
inputStream.close();
outputStream.close();
} catch (Exception e) {
logger.error("释放资源出错!", e);
}
}
}
/**
* 从输入流中获取字符串
*/
public static String getString(InputStream is) {
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (Exception e) {
logger.error("Stream 转 String 出错!", e);
throw new RuntimeException(e);
}
return sb.toString();
}
}
13. 字符串操作工具类
package org.smart4j.framework.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
/**
* 字符串操作工具类
*
* @author huangyong
* @since 1.0
*/
public class StringUtil {
/**
* 字符串分隔符
*/
public static final String SEPARATOR = String.valueOf((char) 29);
/**
* 判断字符串是否非空
*/
public static boolean isNotEmpty(String str) {
return StringUtils.isNotEmpty(str);
}
/**
* 判断字符串是否为空
*/
public static boolean isEmpty(String str) {
return StringUtils.isEmpty(str);
}
/**
* 若字符串为空,则取默认值
*/
public static String defaultIfEmpty(String str, String defaultValue) {
return StringUtils.defaultIfEmpty(str, defaultValue);
}
/**
* 替换固定格式的字符串(支持正则表达式)
*/
public static String replaceAll(String str, String regex, String replacement) {
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, replacement);
}
m.appendTail(sb);
return sb.toString();
}
/**
* 是否为数字(整数或小数)
*/
public static boolean isNumber(String str) {
return NumberUtils.isNumber(str);
}
/**
* 是否为十进制数(整数)
*/
public static boolean isDigits(String str) {
return NumberUtils.isDigits(str);
}
/**
* 将驼峰风格替换为下划线风格
*/
public static String camelhumpToUnderline(String str) {
Matcher matcher = Pattern.compile("[A-Z]").matcher(str);
StringBuilder builder = new StringBuilder(str);
for (int i = 0; matcher.find(); i++) {
builder.replace(matcher.start() + i, matcher.end() + i, "_" + matcher.group().toLowerCase());
}
if (builder.charAt(0) == ''_'') {
builder.deleteCharAt(0);
}
return builder.toString();
}
/**
* 将下划线风格替换为驼峰风格
*/
public static String underlineToCamelhump(String str) {
Matcher matcher = Pattern.compile("_[a-z]").matcher(str);
StringBuilder builder = new StringBuilder(str);
for (int i = 0; matcher.find(); i++) {
builder.replace(matcher.start() - i, matcher.end() - i, matcher.group().substring(1).toUpperCase());
}
if (Character.isUpperCase(builder.charAt(0))) {
builder.replace(0, 1, String.valueOf(Character.toLowerCase(builder.charAt(0))));
}
return builder.toString();
}
/**
* 分割固定格式的字符串
*/
public static String[] splitString(String str, String separator) {
return StringUtils.splitByWholeSeparator(str, separator);
}
/**
* 将字符串首字母大写
*/
public static String firstToUpper(String str) {
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}
/**
* 将字符串首字母小写
*/
public static String firstToLower(String str) {
return Character.toLowerCase(str.charAt(0)) + str.substring(1);
}
/**
* 转为帕斯卡命名方式(如:FooBar)
*/
public static String toPascalStyle(String str, String seperator) {
return StringUtil.firstToUpper(toCamelhumpStyle(str, seperator));
}
/**
* 转为驼峰命令方式(如:fooBar)
*/
public static String toCamelhumpStyle(String str, String seperator) {
return StringUtil.underlineToCamelhump(toUnderlineStyle(str, seperator));
}
/**
* 转为下划线命名方式(如:foo_bar)
*/
public static String toUnderlineStyle(String str, String seperator) {
str = str.trim().toLowerCase();
if (str.contains(seperator)) {
str = str.replace(seperator, "_");
}
return str;
}
/**
* 转为显示命名方式(如:Foo Bar)
*/
public static String toDisplayStyle(String str, String seperator) {
String displayName = "";
str = str.trim().toLowerCase();
if (str.contains(seperator)) {
String[] words = StringUtil.splitString(str, seperator);
for (String word : words) {
displayName += StringUtil.firstToUpper(word) + " ";
}
displayName = displayName.trim();
} else {
displayName = StringUtil.firstToUpper(str);
}
return displayName;
}
}
14. Web 操作工具类
package org.smart4j.framework.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.smart4j.framework.FrameworkConstant;
/**
* Web 操作工具类
*
* @author huangyong
* @since 1.0
*/
public class WebUtil {
private static final Logger logger = LoggerFactory.getLogger(WebUtil.class);
/**
* 将数据以 JSON 格式写入响应中
*/
public static void writeJSON(HttpServletResponse response, Object data) {
try {
// 设置响应头
response.setContentType("application/json"); // 指定内容类型为 JSON 格式
response.setCharacterEncoding(FrameworkConstant.UTF_8); // 防止中文乱码
// 向响应中写入数据
PrintWriter writer = response.getWriter();
writer.write(JsonUtil.toJSON(data)); // 转为 JSON 字符串
writer.flush();
writer.close();
} catch (Exception e) {
logger.error("在响应中写数据出错!", e);
throw new RuntimeException(e);
}
}
/**
* 将数据以 HTML 格式写入响应中(在 JS 中获取的是 JSON 字符串,而不是 JSON 对象)
*/
public static void writeHTML(HttpServletResponse response, Object data) {
try {
// 设置响应头
response.setContentType("text/html"); // 指定内容类型为 HTML 格式
response.setCharacterEncoding(FrameworkConstant.UTF_8); // 防止中文乱码
// 向响应中写入数据
PrintWriter writer = response.getWriter();
writer.write(JsonUtil.toJSON(data)); // 转为 JSON 字符串
writer.flush();
writer.close();
} catch (Exception e) {
logger.error("在响应中写数据出错!", e);
throw new RuntimeException(e);
}
}
/**
* 从请求中获取所有参数(当参数名重复时,用后者覆盖前者)
*/
public static Map<String, Object> getRequestParamMap(HttpServletRequest request) {
Map<String, Object> paramMap = new LinkedHashMap<String, Object>();
try {
String method = request.getMethod();
if (method.equalsIgnoreCase("put") || method.equalsIgnoreCase("delete")) {
String queryString = CodecUtil.decodeURL(StreamUtil.getString(request.getInputStream()));
if (StringUtil.isNotEmpty(queryString)) {
String[] qsArray = StringUtil.splitString(queryString, "&");
if (ArrayUtil.isNotEmpty(qsArray)) {
for (String qs : qsArray) {
String[] array = StringUtil.splitString(qs, "=");
if (ArrayUtil.isNotEmpty(array) && array.length == 2) {
String paramName = array[0];
String paramValue = array[1];
if (checkParamName(paramName)) {
if (paramMap.containsKey(paramName)) {
paramValue = paramMap.get(paramName) + StringUtil.SEPARATOR + paramValue;
}
paramMap.put(paramName, paramValue);
}
}
}
}
}
} else {
Enumeration<String> paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = paramNames.nextElement();
if (checkParamName(paramName)) {
String[] paramValues = request.getParameterValues(paramName);
if (ArrayUtil.isNotEmpty(paramValues)) {
if (paramValues.length == 1) {
paramMap.put(paramName, paramValues[0]);
} else {
StringBuilder paramValue = new StringBuilder("");
for (int i = 0; i < paramValues.length; i++) {
paramValue.append(paramValues[i]);
if (i != paramValues.length - 1) {
paramValue.append(StringUtil.SEPARATOR);
}
}
paramMap.put(paramName, paramValue.toString());
}
}
}
}
}
} catch (Exception e) {
logger.error("获取请求参数出错!", e);
throw new RuntimeException(e);
}
return paramMap;
}
private static boolean checkParamName(String paramName) {
return !paramName.equals("_"); // 忽略 jQuery 缓存参数
}
/**
* 转发请求
*/
public static void forwardRequest(String path, HttpServletRequest request, HttpServletResponse response) {
try {
request.getRequestDispatcher(path).forward(request, response);
} catch (Exception e) {
logger.error("转发请求出错!", e);
throw new RuntimeException(e);
}
}
/**
* 重定向请求
*/
public static void redirectRequest(String path, HttpServletRequest request, HttpServletResponse response) {
try {
response.sendRedirect(request.getContextPath() + path);
} catch (Exception e) {
logger.error("重定向请求出错!", e);
throw new RuntimeException(e);
}
}
/**
* 发送错误代码
*/
public static void sendError(int code, String message, HttpServletResponse response) {
try {
response.sendError(code, message);
} catch (Exception e) {
logger.error("发送错误代码出错!", e);
throw new RuntimeException(e);
}
}
/**
* 判断是否为 AJAX 请求
*/
public static boolean isAJAX(HttpServletRequest request) {
return request.getHeader("X-Requested-With") != null;
}
/**
* 获取请求路径
*/
public static String getRequestPath(HttpServletRequest request) {
String servletPath = request.getServletPath();
String pathInfo = StringUtil.defaultIfEmpty(request.getPathInfo(), "");
return servletPath + pathInfo;
}
/**
* 从 Cookie 中获取数据
*/
public static String getCookie(HttpServletRequest request, String name) {
String value = "";
try {
Cookie[] cookieArray = request.getCookies();
if (cookieArray != null) {
for (Cookie cookie : cookieArray) {
if (StringUtil.isNotEmpty(name) && name.equals(cookie.getName())) {
value = CodecUtil.decodeURL(cookie.getValue());
break;
}
}
}
} catch (Exception e) {
logger.error("获取 Cookie 出错!", e);
throw new RuntimeException(e);
}
return value;
}
/**
* 下载文件
*/
public static void downloadFile(HttpServletResponse response, String filePath) {
try {
String originalFileName = FilenameUtils.getName(filePath);
String downloadedFileName = new String(originalFileName.getBytes("GBK"), "ISO8859_1"); // 防止中文乱码
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename=\"" + downloadedFileName + "\"");
InputStream inputStream = new BufferedInputStream(new FileInputStream(filePath));
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
StreamUtil.copyStream(inputStream, outputStream);
} catch (Exception e) {
logger.error("下载文件出错!", e);
throw new RuntimeException(e);
}
}
/**
* 设置 Redirect URL 到 Session 中
*/
public static void setRedirectUrl(HttpServletRequest request, String sessionKey) {
if (!isAJAX(request)) {
String requestPath = getRequestPath(request);
request.getSession().setAttribute(sessionKey, requestPath);
}
}
/**
* 创建验证码
*/
public static String createCaptcha(HttpServletResponse response) {
StringBuilder captcha = new StringBuilder();
try {
// 参数初始化
int width = 60; // 验证码图片的宽度
int height = 25; // 验证码图片的高度
int codeCount = 4; // 验证码字符个数
int codeX = width / (codeCount + 1); // 字符横向间距
int codeY = height - 4; // 字符纵向间距
int fontHeight = height - 2; // 字体高度
int randomSeed = 10; // 随机数种子
char[] codeSequence = { // 验证码中可出现的字符
''0'', ''1'', ''2'', ''3'', ''4'', ''5'', ''6'', ''7'', ''8'', ''9''
};
// 创建图像
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
// 将图像填充为白色
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
// 设置字体
g.setFont(new Font("Courier New", Font.BOLD, fontHeight));
// 绘制边框
g.setColor(Color.BLACK);
g.drawRect(0, 0, width - 1, height - 1);
// 产生随机干扰线(160条)
g.setColor(Color.WHITE);
// 创建随机数生成器
Random random = new Random();
for (int i = 0; i < 160; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
// 生成随机验证码
int red, green, blue;
for (int i = 0; i < codeCount; i++) {
// 获取随机验证码
String validateCode = String.valueOf(codeSequence[random.nextInt(randomSeed)]);
// 随机构造颜色值
red = random.nextInt(255);
green = random.nextInt(255);
blue = random.nextInt(255);
// 将带有颜色的验证码绘制到图像中
g.setColor(new Color(red, green, blue));
g.drawString(validateCode, (i + 1) * codeX - 6, codeY);
// 将产生的随机数拼接起来
captcha.append(validateCode);
}
// 禁止图像缓存
response.setHeader("Cache-Control", "no-store");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
// 设置响应类型为 JPEG 图片
response.setContentType("image/jpeg");
// 将缓冲图像写到 Servlet 输出流中
ServletOutputStream sos = response.getOutputStream();
ImageIO.write(bi, "jpeg", sos);
sos.close();
} catch (Exception e) {
logger.error("创建验证码出错!", e);
throw new RuntimeException(e);
}
return captcha.toString();
}
/**
* 是否为 IE 浏览器
*/
public boolean isIE(HttpServletRequest request) {
String agent = request.getHeader("User-Agent");
return agent != null && agent.contains("MSIE");
}
}
.a文件编译到.framework中,再将framework导入项目,引用出错
我将.a编译到framework中,然后将framework编译到我项目里面去,引用封装在.a的类和接口,编译报错,链接失败,这个如何解决啊?
chapter3 怎么添加smart-framework这个项目的依赖
@黄勇 你好,想跟你请教个问题:我买了您的框架探险(从零开始写java web 框架)的那本书,在74页那里给chapter3添加smart-framework version 1.0.0 这里 ,version 1.0.0这个始终是红色,请问chapter3 怎么添加smart-framework这个项目的依赖
Django-rest-framework 接口实现 rest_framework 中有已经定义好的 工具类 mixins generics viewsets
rest_framework.mixins
请求业务 的 5 种实现
mixin(混合类):不能单独使用,和其它类搭配起来使用(利用了Python支持多继承)
rest_framework.mixins
imput 业务的 主要逻辑都在这里CreateModelMixin
创建对象 post 请求ListModelMixin
查询所有的对象 get请求RetrieveModelMixin
查询一个对象 get请求UpdateModelMixin
更改一个对象 put 请求DestroyModelMixin
删除一个请求 delete 请求
rest_framework.generics
实际使用时 需要调用的类
实际操作时根据 相应的需求来查询并继承
定义的类的 视图操作 上面实现了 orm 操作 GenericAPIView
以及 增删改查查的 操作 分类 多种选项 根据实际情况分类继承
rest_framework.viewsets
没有实际的 操作 只是对类进行了 归类的继承 方便使用
-
rest_framework.viewsets`中还封装好了其他的方法 一次性继承
from rest_framework.viewsets import ReadOnlyModelViewSet
ReadOnlyModelViewSet
封住了 两个查询的 方法 以及视图配置ModelViewSet
封装了 视图配置以及5 个方法 直接继承这一个方法 完成5中操作
-
使用
ModelViewSet
合成的写法 就要-
对路由进行设置 actions={''get'':''list'' .....} 进行归类
url(r''authors/$'', views.AuthorViewSet.as_view( actions={''get'': ''list'', ''post'': ''create''})), # 作者列表 url(r''authors/(?P<pk>\d+)/$'', views.AuthorViewSet.as_view( actions={''get'': ''retrieve'', ''put'': ''update'', ''delete'': ''destroy''})), # 作者详情
-
或者使用 集成的写法 只写一个路由
from rest_framework.routers import urlpatterns router = DefaurtRouter() # 设置路由应对应的 视图 router.register(''authors'', views.AuthorViewSet) router.register(''books'', views.BooksViewSet) # 将生成的 路由添加到 urlpatterns 中 默认路由 urlpatterns += router.urls
-
简化写法
视图只需要写一个就可以完成相应的操作
视图中 注意在路由中也要做一些修改
分开的写法:
# 导入配置类
from rest_framework.viewsets import GenericViewSet
# 分开写 可以通过继承方式来 实现某种功能 路有中也必须分开写
导入5 个 混合类 配合使用
from rest_framework.mixins import CreateModelMixin, ListModelMixin, UpdateModelMixin, DestroyModelMixin, \
RetrieveModelMixin
# 有 get post 请求
class BooksList(GenericViewSet, CreateModelMixin, ListModelMixin):
queryset = models.Books.objects.all()
serializer_class = BooksModelSerializer
# get put delete 请求
class BookDetail(GenericViewSet, UpdateModelMixin, DestroyModelMixin, RetrieveModelMixin):
queryset = models.Books.objects.all()
serializer_class = BooksModelSerializer
写成一个的 写法
from rest_framework.viewsets import ModelViewSet
# 导入rest_framework已经 封装好的 5 种请求类 以及配置类
# 直接继承 就可以 使用返回 5 中请求
class AuthorViewSet(ModelViewSet):
"""
list()
create()
retrieve()
update()
destroy()
"""
queryset = models.Author.objects.all()
serializer_class = AuthorModelSerializer
路由中
一定要写 actions={}的 参数 字典中的 key 对应小写的 请求方式 value 对应请求 应该执行的 方法
如果 忘了 可以在 rest_framework.viewsets 中 查看 具体 对应的 方法名字
url(r''authors/$'', views.AuthorViewSet.as_view(actions={''get'': ''list'', ''post'': ''create''})), # 作者列表
url(r''authors/(?P<pk>\d+)/$'', views.AuthorViewSet.as_view(
actions={''get'': ''retrieve'', ''put'': ''update'', ''delete'': ''destroy''})
), # 作者详情
路由也可以 写成一个 由系统自动分配路由 urlpatterns
from rest_framework.routers import urlpatterns
router = DefaurtRouter(
# 设置路由应对应的 视图
router.register(''authors'', views.AuthorViewSet)
router.register(''books'', views.BooksViewSet)
将生成的 路由添加到 urlpatterns 中 默认路由
urlpatterns += router.urls
#####此方法 可以在路由中 使用 .json 直接获取json 数据
http://127.0.0.1:8000/books.json
从地址栏获取 ? 参数
request.query_params.get(''category'')
generics
使用 封装了 所有的 增删改查查 操作
-
from rest_framework import generics
-
直接继承内部封装的方法
-
不必在 路由中 写
actions={''get'': ''list'', ''post'': ''create''}
来定义 具体的 对应操作 -
class ListAPIView(mixins.ListModelMixin, GenericAPIView): """ Concrete view for listing a queryset. """ def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs)
-
类中已经定义好了 方法 调用对应的 Mixin 类中的 方法
**只需要 定义 **
-
queryset = models.Course.objects.all() serializer_class = CourseModelSerializer
-
Eclipse轻松玩转SmartFramework
SmartFramework框架和 SmartSample都是使用Maven构建,使用IDEA开发的。对于像我这样使用Eclipse,又不熟悉Maven的人来说,想玩转smart多少有些难度。这里是我在Eclipse中运行smart-sample的方法,分享给大家,希望对想玩smart的同学有所帮助。下面分四个步骤介绍:
第一步:准备运行环境
1.数据库 :MySQL5.5 / MariaDB 5 +;
2.Web服务器:Tomcat7.0 +;
3.下载Smart-Framework框架源码;
4.下载 Smart-Plugin-Cache插件源码;
5.下载Smart-Sample示例源码;
6.下载Smart Sample For Eclipse 源码;
说明:这里不使用Maven,也不使用Git版本控制;如果想使用Git管理项目可参考 《Eclipse使用EGit管理git@OSC项目》
第二步:构建项目
在Eclipse中构建smart-sample示例项目有两种方式:
1.方式一
直接下载 Smart Sample For Eclipse :这是一个完整的Eclipse项目,直接导入Eclipse中即可运行。项目中已经包含SmartFramework、SamrtCache的jar包和他们的依赖jar包。这是最简单的方式,有可能你不喜欢就这么简单的把项目跑起来,你想享受一下构建项目的完整过程,那么方式二就是一步一步从源码构建项目的步骤。
2.方式二
使用源码构建Smart-Sample示例:因为Maven项目的结构和Eclipse web项目结构不一样,所以这里使用源码构建Eclipse项目:
1).创建一个名为Smart-Sample的java web项目;
2).将Smart-Sample源码src/main/java/下的 com 目录复制 到 新创建的web项目src下;
3).在项目的Java Resources下新建一个名为Smart的Source Folder将Smart-Framework源码src/main/java/下的com目录复制到新创建的Smart源码目录;
4).同样在 Java Resources下创 建一个名为SmartPlugin的 Source F ol der 将 Smart-Plugin-Cache源码src/ main/java/下的 com 目录复制到新创建的SmartPlugin源码目录;
5).将Smart-Sample源码src/main/resources/中的文件复制到新创建的web项目的src中;
6).复制Smart-Sample源码src/main/webapp/中的文件到新建项目的WebContent目录中;
7).将Smart-Samlpe-For-Eclipse项目WebContent/WEB-INF/下的lib目录复制到新建项目的WebContent/WEB-INF/中,并将所有jar包添加到bulid path中,别忘了添加JUnit4;
![]()
到这里Smart-Sample就构建完成了,当然这不是最佳的方式,最佳方式是使用Maven和 Git构建和管理项目。
第三步:初始化数据库
1.导入示例数据:在数据库中创建一个名为smart的数据库,将smart-sample或者smart-samlpe-for-eclipse源码中doc目录中的sample.sql导入执行。
2.修改数据库配置:代开新建项目src目录中的config.properties文件,修改jdbc属性为你自己数据库的相关属性即可。
![]()
说明: MariaDB5本质上就是MySQl5,这里配置都一样。
第四步:运行项目
将构建的 Smart-Sample项目部署到Tomcat7中,启动Tomcat,访问http://localhost:8080/smart-sample/,就看到登录页面了。使用admin/admin登录后,就可以尽情体验Smart了!
![]()
![]()
特别说明
这里Tomcat要使用Tomcat7以上版本,因为Smart是基于Servlet3.0标准的。
如果创建的项目名称为Smart-Sample首字母大写,需要将 config.properties文件中的 app.name改为Smart-Sample,访问路径也应该是大写,将www / asset / script / global.js中的 var BASE = ''/smart-sample'' 改为var BASE = ''/Smart-Sample''!
原文地址:《Eclipse轻松玩转SmartFramework》
我们今天的关于java 常用工具类和从开源项目 smartframework 项目 copy 过来备用的分享就到这里,谢谢您的阅读,如果想了解更多关于.a文件编译到.framework中,再将framework导入项目,引用出错、chapter3 怎么添加smart-framework这个项目的依赖、Django-rest-framework 接口实现 rest_framework 中有已经定义好的 工具类 mixins generics viewsets、Eclipse轻松玩转SmartFramework的相关信息,可以在本站进行搜索。
本文标签: