# ibsm-common **Repository Path**: ibsm/ibsm-common ## Basic Information - **Project Name**: ibsm-common - **Description**: 总结常用开发工具函数,组件业务实现,插件功能性代码;目的解决日常实际工作开发需要,用合适的方法,在单位时间内,高效高质量实现业务功能【如:Jpush、Email、阿里大于、分布式锁、Httpclient等】 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 5 - **Forks**: 7 - **Created**: 2016-11-18 - **Last Updated**: 2024-11-03 ## Categories & Tags **Categories**: utils **Tags**: None ## README #常用工具类合集 1. 统一web后端处理 ``` package com.hm.car.util; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import com.hm.common.ServerResponse; /** * @author shishun.wang * @date 2016年12月15日 下午12:00:07 * @version 1.0 * @describe */ public class ControllerResult { public static ResponseEntity> success(T result) { return new ResponseEntity>(new ServerResponse().success(result), HttpStatus.OK); } public static ResponseEntity> failed(String message) { return new ResponseEntity>(new ServerResponse().failure(message), HttpStatus.BAD_REQUEST); } public static ResponseEntity> failed(Exception e) { return new ResponseEntity>(new ServerResponse().failure(e.getMessage()), HttpStatus.BAD_REQUEST); } } ``` 2. java模型数据快速拷贝 ``` package com.hm.car.util; import java.lang.reflect.Field; import java.util.Arrays; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.util.ReflectionUtils; import com.hm.common.util.CommonUtil; /** * @author shishun.wang * @date 2016年12月14日 上午10:11:15 * @version 1.0 * @describe */ public class BeanUtil { private static final String MODEL_ID_FIELD = "id"; public static final void copyProperties(Object source, Object target, String... ignoreProperties) { if (com.hm.common.util.CommonUtil.isAnyEmpty(source, target)) { return; } BeanUtils.copyProperties(source, target, ignoreProperties); // Trying copy id field if (com.hm.common.util.CommonUtil.isNotEmpty(ignoreProperties) && Arrays.asList(ignoreProperties).contains(MODEL_ID_FIELD)) { return; } Field targetFiled = ReflectionUtils.findField(target.getClass(), MODEL_ID_FIELD, String.class); if (targetFiled == null) { return; } Field sourceFiled = ReflectionUtils.findField(source.getClass(), MODEL_ID_FIELD); if (sourceFiled == null) { return; } try { sourceFiled.setAccessible(true); Object sourceId = sourceFiled.get(source); if (sourceId == null) { return; } targetFiled.setAccessible(true); if (sourceId instanceof String) { ReflectionUtils.setField(targetFiled, target, sourceId); } else { ReflectionUtils.setField(targetFiled, target, sourceId.toString()); } } catch (IllegalArgumentException | IllegalAccessException e) { LoggerFactory.getLogger(CommonUtil.class).error("Failed to reflect set id properties", e); } } } ``` 3、maven项目配置。 ``` nexus-releases deployment 1234567 nexus-snapshots deployment 1234567 hm-snapshots admin 1234567 nexus-snapshots nexus-snapshots http://192.168.3.100:8888/nexus/content/groups/public-snapshots nexus-releases nexus-releases http://192.168.3.100:8888/nexus/content/groups/public hm-snapshots hm-snapshots http://120.92.147.60:8081/nexus/content/repositories/hm-snapshots thirdparty thirdparty http://120.92.147.60:8081/nexus/content/repositories/thirdparty central-maven * http://central.maven.org/maven2/ central-repo1 * http://repo1.maven.org/maven2/ nexus true hm-snapshots hm-snapshots http://120.92.147.60:8081/nexus/content/repositories/hm-snapshots true true thirdparty thirdparty http://120.92.147.60:8081/nexus/content/repositories/thirdparty true true nexus-snapshots nexus snapshots true false http://192.168.3.100:8888/nexus/content/groups/public-snapshots nexus-releases nexus releases false true http://192.168.3.100:8888/nexus/content/groups/public maven maven http://repo1.maven.org/maven2/ central-maven http://central.maven.org/maven2/ apache.snapshots http://people.apache.org/maven-snapshot-repository/ nexus-world-repo world-repo http://search.maven.org/ nexus-osc Nexus osc http://maven.oschina.net/content/groups/public/ mirrors.ibiblio.org mirrors.ibiblio.org http://mirrors.ibiblio.org/maven2/ nexus-osc-thirdparty Nexus osc thirdparty http://maven.oschina.net/content/repositories/thirdparty/ thirdparty thirdparty http://120.92.147.60:8081/nexus/content/repositories/thirdparty/ nexus-releases nexus releases http://192.168.3.100:8888/nexus/content/groups/public false true nexus-snapshots nexus snapshots http://192.168.3.100:8888/nexus/content/groups/public-snapshots true false hm-snapshots hm-snapshots http://120.92.147.60:8081/nexus/content/repositories/hm-snapshots true true thirdparty thirdparty http://120.92.147.60:8081/nexus/content/repositories/thirdparty true true ```