├── NHVersion ├── .gitignore ├── lib │ ├── org.springframework.beans-3.1.1.RELEASE.jar │ ├── org.springframework.context-3.1.1.RELEASE.jar │ └── org.springframework.core-3.1.1.RELEASE.jar ├── pom.xml └── src │ └── main │ └── java │ └── com │ └── jeffreyning │ └── nhversion │ └── common │ └── version │ ├── cmd │ └── IControllerCommand.java │ ├── mapping │ ├── CommonControllerMapping.java │ └── ControllerMappingAnno.java │ └── util │ ├── NHBeanUtil.java │ └── VersionMappingUtil.java ├── NHVersionDemo ├── .gitignore └── src │ └── com │ └── jeffreyning │ └── nhversion │ └── demo │ ├── Demo.java │ └── controller │ ├── NHVersionController.java │ ├── NoNHVersionController.java │ └── cmd │ ├── CalcuCmd1.java │ ├── CalcuCmd2.java │ └── CalcuCmd3.java ├── NHVersionSupportSpringDemo ├── .gitignore ├── lib │ ├── commons-logging-1.1.1.jar │ ├── org.springframework.asm-3.1.1.RELEASE.jar │ ├── org.springframework.beans-3.1.1.RELEASE.jar │ ├── org.springframework.context-3.1.1.RELEASE.jar │ ├── org.springframework.context.support-3.1.1.RELEASE.jar │ ├── org.springframework.core-3.1.1.RELEASE.jar │ └── org.springframework.expression-3.1.1.RELEASE.jar └── src │ ├── applicationContext.xml │ └── com │ └── jeffreyning │ └── nhversion │ └── demo │ ├── Demo.java │ └── controller │ ├── FrontVersionChangeController.java │ ├── NHVersionController.java │ ├── NoNHVersionController.java │ └── cmd │ ├── CalcuCmd1.java │ ├── CalcuCmd2.java │ └── CalcuCmd3.java ├── README.md ├── nhversion-1.0.jar └── nhversion-1.1.jar /NHVersion/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | bin 5 | target 6 | -------------------------------------------------------------------------------- /NHVersion/lib/org.springframework.beans-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersion/lib/org.springframework.beans-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersion/lib/org.springframework.context-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersion/lib/org.springframework.context-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersion/lib/org.springframework.core-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersion/lib/org.springframework.core-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersion/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | com.github.jeffreyning 4 | nhversion 5 | 1.3.0-RELEASE 6 | com.github.jeffreyning:nhversion 7 | nhversion 8 | https://github.com/jeffreyning/NHVersion 9 | 10 | 11 | The Apache License, Version 2.0 12 | http://www.apache.org/licenses/LICENSE-2.0.txt 13 | 14 | 15 | 16 | 17 | ninghao 18 | jeffreyning@aliyun.com 19 | jeffreyningsoftware 20 | jeffreyningsoftware.com 21 | 22 | 23 | 24 | scm:git:git@github.com:jeffreyning/NHVersion.git 25 | scm:git:git@github.com:jeffreyning/NHVersion.git 26 | git@github.com:jeffreyning/NHVersion.git 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 3.1 34 | 35 | 1.6 36 | 1.6 37 | utf-8 38 | 39 | ${project.basedir}/lib 40 | 41 | 42 | 43 | 44 | 45 | org.apache.maven.plugins 46 | maven-gpg-plugin 47 | 48 | 49 | sign-artifacts 50 | verify 51 | 52 | sign 53 | 54 | 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-source-plugin 60 | 2.2.1 61 | 62 | 63 | attach-sources 64 | 65 | jar-no-fork 66 | 67 | 68 | 69 | 70 | 71 | org.apache.maven.plugins 72 | maven-javadoc-plugin 73 | 2.9.1 74 | 75 | 76 | attach-javadocs 77 | 78 | jar 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | org.sonatype.plugins 87 | nexus-staging-maven-plugin 88 | 1.6 89 | true 90 | 91 | ossrh 92 | https://oss.sonatype.org/ 93 | false 94 | true 95 | 20 96 | 20 97 | true 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | ossrh 106 | https://oss.sonatype.org/content/repositories/snapshots 107 | 108 | 109 | ossrh 110 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /NHVersion/src/main/java/com/jeffreyning/nhversion/common/version/cmd/IControllerCommand.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.common.version.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public abstract class IControllerCommand { 7 | public final static String RETOBJ = "retObj"; 8 | public final static String EXECSTATUS = "execStatus"; 9 | 10 | public Map createRetMapSimple(Object retObj) { 11 | Map retMap = new HashMap(); 12 | retMap.put(RETOBJ, retObj); 13 | return retMap; 14 | } 15 | 16 | public abstract Map execute(Map paramMap); 17 | } 18 | -------------------------------------------------------------------------------- /NHVersion/src/main/java/com/jeffreyning/nhversion/common/version/mapping/CommonControllerMapping.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.common.version.mapping; 2 | 3 | import java.io.File; 4 | import java.io.FileFilter; 5 | import java.io.IOException; 6 | import java.net.JarURLConnection; 7 | import java.net.URL; 8 | import java.net.URLDecoder; 9 | import java.util.Enumeration; 10 | import java.util.Iterator; 11 | import java.util.LinkedHashSet; 12 | import java.util.Map; 13 | import java.util.Set; 14 | import java.util.TreeMap; 15 | import java.util.concurrent.ConcurrentHashMap; 16 | import java.util.jar.JarEntry; 17 | import java.util.jar.JarFile; 18 | 19 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 20 | import com.jeffreyning.nhversion.common.version.util.NHBeanUtil; 21 | 22 | /** 23 | * controller与cmd版本映射工具 24 | * 25 | * @author ninghao 26 | * 27 | */ 28 | public class CommonControllerMapping { 29 | @SuppressWarnings("rawtypes") 30 | private static Map confMap = new ConcurrentHashMap(); 31 | 32 | /** 33 | * 设置映射关系 34 | * 35 | * @param controllerName 36 | * cotroller名称 37 | * @param funcName 38 | * 成员方法名称 39 | * @param funcVer 40 | * 成员方法版本 41 | * @param cmd 42 | * 命令对象 43 | * @exception runtimeException 44 | * funcVer error 45 | */ 46 | @SuppressWarnings({ "rawtypes", "unchecked" }) 47 | public static void setMapping(String controllerName, String funcName, 48 | String funcVer, IControllerCommand cmd) { 49 | int version = 0; 50 | version = getVersionInt(funcVer); 51 | if (version < 0) { 52 | throw new RuntimeException("funcVer error during setMapping"); 53 | } 54 | if (controllerName == null || "".equals(controllerName)) { 55 | throw new RuntimeException("controllerName error during setMapping"); 56 | } 57 | if (funcName == null || "".equals(funcName)) { 58 | throw new RuntimeException("funcName error during setMapping"); 59 | } 60 | if (cmd == null) { 61 | throw new RuntimeException("cmd error during setMapping"); 62 | } 63 | 64 | Map controllerMap = (Map) confMap.get(controllerName); 65 | if (controllerMap == null) { 66 | controllerMap = new ConcurrentHashMap(); 67 | confMap.put(controllerName, controllerMap); 68 | } 69 | Map funcMap = (Map) controllerMap.get(funcName); 70 | if (funcMap == null) { 71 | funcMap = new TreeMap(); 72 | controllerMap.put(funcName, funcMap); 73 | } 74 | funcMap.put(version, cmd); 75 | 76 | } 77 | 78 | /** 79 | * 查询映射关系并触发cmd执行,version支持自动向下寻找,默认返回retObj对象 80 | * 81 | * @param controllerName 82 | * cotroller名称 83 | * @param funcName 84 | * 成员方法名称 85 | * @param funcVer 86 | * 成员方法版本 87 | * @param paramMap 88 | * 参数 89 | */ 90 | public static Object execVersionMappingSimple(String controllerName, 91 | String funcName, String funcVer, Map paramMap) { 92 | Map retMap = CommonControllerMapping.execVersionMapping(controllerName, 93 | funcName, funcVer, paramMap); 94 | if (retMap != null) { 95 | return retMap.get(IControllerCommand.RETOBJ); 96 | } 97 | return null; 98 | } 99 | 100 | /** 101 | * 查询映射关系并触发cmd执行,version支持自动向下寻找 102 | * 103 | * @param controllerName 104 | * cotroller名称 105 | * @param funcName 106 | * 成员方法名称 107 | * @param funcVer 108 | * 成员方法版本 109 | * @param paramMap 110 | * 参数 111 | */ 112 | @SuppressWarnings({ "rawtypes", "unchecked" }) 113 | public static Map execVersionMapping(String controllerName, 114 | String funcName, String funcVer, Map paramMap) { 115 | int version = 0; 116 | version = getVersionInt(funcVer); 117 | if (version < 0) { 118 | throw new RuntimeException("version format<0 error"); 119 | } 120 | 121 | Map controllerMap = (Map) confMap.get(controllerName); 122 | if (controllerMap == null) { 123 | throw new RuntimeException("controllerMap is null"); 124 | } 125 | 126 | TreeMap funcMap = (TreeMap) controllerMap.get(funcName); 127 | if (funcMap == null) { 128 | throw new RuntimeException("funcMap is null"); 129 | } 130 | 131 | Object key = funcMap.floorKey(version); 132 | if (key == null) { 133 | throw new RuntimeException("version key is null"); 134 | } 135 | 136 | IControllerCommand command = (IControllerCommand) funcMap.get(key); 137 | if (command == null) { 138 | throw new RuntimeException("command is null"); 139 | } 140 | 141 | Map retMap = command.execute(paramMap); 142 | return retMap; 143 | 144 | } 145 | 146 | // 将版本字符串转为int 147 | public static int getVersionInt(String verStr) { 148 | int version = 0; 149 | if (verStr == null || "".equals(verStr)) { 150 | throw new RuntimeException("verStr is null"); 151 | } 152 | String versionStr = verStr.toLowerCase().replace("v", ""); 153 | String[] verArray = versionStr.split("_"); 154 | try { 155 | int size = verArray.length; 156 | for (int i = 0; i < size && i < 3; i++) { 157 | if (i == 0) { 158 | String tempStr = verArray[0]; 159 | int tempInt = Integer.valueOf(tempStr); 160 | version = tempInt * 100 * 100; 161 | } else if (i == 1) { 162 | String tempStr = verArray[1]; 163 | int tempInt = Integer.valueOf(tempStr); 164 | version = version + tempInt * 100; 165 | } else if (i == 2) { 166 | String tempStr = verArray[2]; 167 | int tempInt = Integer.valueOf(tempStr); 168 | version = version + tempInt; 169 | } 170 | } 171 | } catch (Exception e) { 172 | throw new RuntimeException("version format error", e); 173 | } 174 | return version; 175 | } 176 | 177 | /** 178 | * 注册命令对象,根据注解添加注册信息 179 | * 180 | * @param cmd 181 | * 命令对象 182 | * @exception runtimeException 183 | * 没有注解信息 184 | */ 185 | public static void registry(IControllerCommand cmd) { 186 | ControllerMappingAnno annotation = cmd.getClass().getAnnotation( 187 | ControllerMappingAnno.class); 188 | if (annotation == null) { 189 | throw new RuntimeException( 190 | "ControllerCommand not found mapping annotation"); 191 | } 192 | String controllerName = annotation.controllerName(); 193 | String funcName = annotation.funcName(); 194 | String funcVer = annotation.funcVer(); 195 | CommonControllerMapping.setMapping(controllerName, funcName, funcVer, 196 | cmd); 197 | } 198 | 199 | public static void batchRegistry(Set classSet) throws Exception { 200 | Iterator it = classSet.iterator(); 201 | while (it.hasNext()) { 202 | Class c = (Class) it.next(); 203 | ControllerMappingAnno anno = (ControllerMappingAnno) c 204 | .getAnnotation(ControllerMappingAnno.class); 205 | if (anno == null) { 206 | continue; 207 | } 208 | String beanId=anno.beanId(); 209 | IControllerCommand ic=null; 210 | if(beanId==null || beanId.equals("")){ 211 | ic=(IControllerCommand) c.newInstance(); 212 | }else{ 213 | ic=(IControllerCommand) NHBeanUtil.getNHBean(beanId); 214 | } 215 | CommonControllerMapping.registry(ic); 216 | } 217 | } 218 | 219 | /** 220 | * 根据包路径批量加载cmd 221 | * 222 | * @param packDir 223 | * 包路径 224 | * @throws Exception 225 | */ 226 | public static void batchRegistryByPackage(String packDir) throws Exception { 227 | Set set = CommonControllerMapping 228 | .getClasses(packDir); 229 | batchRegistry(set); 230 | } 231 | 232 | /** 233 | * 从包package中获取所有的Class 234 | * 235 | * @param pack 236 | * @return 237 | */ 238 | public static Set getClasses(String pack) { 239 | 240 | Set classes = new LinkedHashSet(); 241 | 242 | boolean recursive = true; 243 | 244 | String packageName = pack; 245 | String packageDirName = packageName.replace('.', '/'); 246 | 247 | Enumeration dirs; 248 | try { 249 | dirs = Thread.currentThread().getContextClassLoader() 250 | .getResources(packageDirName); 251 | 252 | while (dirs.hasMoreElements()) { 253 | 254 | URL url = dirs.nextElement(); 255 | 256 | String protocol = url.getProtocol(); 257 | 258 | if ("file".equals(protocol)) { 259 | 260 | String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); 261 | 262 | findAndAddClassesInPackageByFile(packageName, filePath, 263 | recursive, classes); 264 | } else if ("jar".equals(protocol)) { 265 | 266 | JarFile jar = null; 267 | try { 268 | 269 | jar = ((JarURLConnection) url.openConnection()) 270 | .getJarFile(); 271 | 272 | Enumeration entries = jar.entries(); 273 | 274 | while (entries.hasMoreElements()) { 275 | 276 | JarEntry entry = entries.nextElement(); 277 | String name = entry.getName(); 278 | 279 | if (name.charAt(0) == '/') { 280 | 281 | name = name.substring(1); 282 | } 283 | 284 | if (name.startsWith(packageDirName)) { 285 | int idx = name.lastIndexOf('/'); 286 | 287 | if (idx != -1) { 288 | 289 | packageName = name.substring(0, idx) 290 | .replace('/', '.'); 291 | } 292 | 293 | if ((idx != -1) || recursive) { 294 | 295 | if (name.endsWith(".class") 296 | && !entry.isDirectory()) { 297 | 298 | String className = name.substring( 299 | packageName.length() + 1, 300 | name.length() - 6); 301 | try { 302 | 303 | classes.add(Class 304 | .forName(packageName + '.' 305 | + className)); 306 | } catch (ClassNotFoundException e) { 307 | 308 | e.printStackTrace(); 309 | } 310 | } 311 | } 312 | } 313 | } 314 | } catch (IOException e) { 315 | 316 | e.printStackTrace(); 317 | } 318 | } 319 | } 320 | } catch (IOException e) { 321 | e.printStackTrace(); 322 | } 323 | 324 | return classes; 325 | } 326 | 327 | /** 328 | * 以文件的形式来获取包下的所有Class 329 | * 330 | * @param packageName 331 | * @param packagePath 332 | * @param recursive 333 | * @param classes 334 | */ 335 | public static void findAndAddClassesInPackageByFile(String packageName, 336 | String packagePath, final boolean recursive, Set classes) { 337 | 338 | File dir = new File(packagePath); 339 | 340 | if (!dir.exists() || !dir.isDirectory()) { 341 | 342 | return; 343 | } 344 | 345 | File[] dirfiles = dir.listFiles(new FileFilter() { 346 | 347 | public boolean accept(File file) { 348 | return (recursive && file.isDirectory()) 349 | || (file.getName().endsWith(".class")); 350 | } 351 | }); 352 | 353 | for (File file : dirfiles) { 354 | 355 | if (file.isDirectory()) { 356 | findAndAddClassesInPackageByFile( 357 | packageName + "." + file.getName(), 358 | file.getAbsolutePath(), recursive, classes); 359 | } else { 360 | 361 | String className = file.getName().substring(0, 362 | file.getName().length() - 6); 363 | try { 364 | classes.add(Thread.currentThread().getContextClassLoader() 365 | .loadClass(packageName + '.' + className)); 366 | } catch (ClassNotFoundException e) { 367 | 368 | e.printStackTrace(); 369 | } 370 | } 371 | } 372 | } 373 | 374 | } 375 | -------------------------------------------------------------------------------- /NHVersion/src/main/java/com/jeffreyning/nhversion/common/version/mapping/ControllerMappingAnno.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.common.version.mapping; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | /** 9 | * 10 | * @author ninghao 11 | * @param controllerName 12 | * controller名称 13 | * @param funcName 14 | * 方法名称 15 | * @param funcVer 16 | * 方法版本 vxx_xx_xx x为数字 不能超过2位数 v10_20_30 => 102030 17 | */ 18 | @Target(ElementType.TYPE) 19 | @Retention(RetentionPolicy.RUNTIME) 20 | public @interface ControllerMappingAnno { 21 | String controllerName(); 22 | 23 | String funcName(); 24 | 25 | String funcVer(); 26 | 27 | String beanId() default ""; 28 | } 29 | -------------------------------------------------------------------------------- /NHVersion/src/main/java/com/jeffreyning/nhversion/common/version/util/NHBeanUtil.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.common.version.util; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | public class NHBeanUtil implements ApplicationContextAware{ 8 | public static ApplicationContext context; 9 | @Override 10 | public void setApplicationContext(ApplicationContext arg0) 11 | throws BeansException { 12 | context=arg0; 13 | } 14 | public static Object getNHBean(String beanId){ 15 | return context.getBean(beanId); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /NHVersion/src/main/java/com/jeffreyning/nhversion/common/version/util/VersionMappingUtil.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.common.version.util; 2 | 3 | import java.util.Map; 4 | import java.util.TreeMap; 5 | 6 | public class VersionMappingUtil { 7 | public static TreeMap versionMap=new TreeMap(); 8 | public static String defaultVer=""; 9 | public static TreeMap getVersionMap() { 10 | return versionMap; 11 | } 12 | 13 | public void setVersionMap(TreeMap versionMap) { 14 | VersionMappingUtil.versionMap = versionMap; 15 | } 16 | 17 | public void setVerProp(Map verProp){ 18 | 19 | versionMap.putAll(verProp); 20 | } 21 | 22 | public static String getDefaultVer() { 23 | return defaultVer; 24 | } 25 | 26 | public void setDefaultVer(String defaultVer) { 27 | VersionMappingUtil.defaultVer = defaultVer; 28 | } 29 | 30 | public static String mappingVer(String frontVer){ 31 | String frontKey = (String) versionMap.floorKey(frontVer); 32 | String backVer=defaultVer; 33 | if (frontKey != null) { 34 | backVer=(String) versionMap.get(frontKey); 35 | } 36 | return backVer; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /NHVersionDemo/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | bin 5 | target 6 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/Demo.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo; 2 | 3 | import com.jeffreyning.nhversion.common.version.mapping.CommonControllerMapping; 4 | import com.jeffreyning.nhversion.demo.controller.NoNHVersionController; 5 | import com.jeffreyning.nhversion.demo.controller.NHVersionController; 6 | 7 | public class Demo { 8 | 9 | /** 10 | * @param args 11 | * @throws Exception 12 | */ 13 | public static void main(String[] args) throws Exception { 14 | CommonControllerMapping.batchRegistryByPackage("com.jeffreyning.nhversion.demo.controller.cmd"); 15 | NoNHVersionController.calcu(1, "v1_0_1"); 16 | NHVersionController.calcu(1,"v1_0_1"); 17 | NoNHVersionController.calcu(1, "v1_0_6"); 18 | NHVersionController.calcu(1,"v1_0_6"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/controller/NHVersionController.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.mapping.CommonControllerMapping; 7 | 8 | public class NHVersionController { 9 | public static int calcu(int param,String version){ 10 | Map paramMap=new HashMap(); 11 | paramMap.put("version", version); 12 | paramMap.put("param", param); 13 | Map retMap=CommonControllerMapping.execVersionMapping("NHVersionController","calcu", version, paramMap); 14 | Integer retInt=(Integer) retMap.get("retInt"); 15 | return retInt; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/controller/NoNHVersionController.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller; 2 | 3 | public class NoNHVersionController { 4 | public static int calcu(int param,String version){ 5 | if(version.equals("v1_0_1")){ 6 | System.out.println("this is nonhversioin v1_0_1"); 7 | return param+1; 8 | }else if(version.equals("v1_0_5")){ 9 | System.out.println("this is nonhversion v1_0_5"); 10 | return param+5; 11 | }else if(version.equals("v1_1_0")){ 12 | System.out.println("this is nonhversion v1_1_0"); 13 | return param+10; 14 | } 15 | System.out.println("this is nonhversion not catch"); 16 | return 0; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd1.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_0_0") 10 | public class CalcuCmd1 extends IControllerCommand{ 11 | 12 | @Override 13 | public Map execute(Map paramMap) { 14 | System.out.println("this is nhversion v1_0_0"); 15 | int param=(Integer) paramMap.get("param"); 16 | int ret=param+1; 17 | Map retMap=new HashMap(); 18 | retMap.put("retInt", ret); 19 | return retMap; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd2.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_0_5") 10 | public class CalcuCmd2 extends IControllerCommand{ 11 | 12 | @Override 13 | public Map execute(Map paramMap) { 14 | System.out.println("this is nhversion v1_0_5"); 15 | int param=(Integer) paramMap.get("param"); 16 | int ret=param+5; 17 | Map retMap=new HashMap(); 18 | retMap.put("retInt", ret); 19 | return retMap; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /NHVersionDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd3.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_1_0") 10 | public class CalcuCmd3 extends IControllerCommand{ 11 | 12 | @Override 13 | public Map execute(Map paramMap) { 14 | System.out.println("this is nhversion v1_1_0"); 15 | int param=(Integer) paramMap.get("param"); 16 | int ret=param+10; 17 | Map retMap=new HashMap(); 18 | retMap.put("retInt", ret); 19 | return retMap; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | bin 5 | target 6 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.asm-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.asm-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.beans-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.beans-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.context-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.context-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.context.support-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.context.support-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.core-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.core-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/lib/org.springframework.expression-3.1.1.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/lib/org.springframework.expression-3.1.1.RELEASE.jar -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/Demo.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/Demo.java -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/FrontVersionChangeController.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/FrontVersionChangeController.java -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/NHVersionController.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.mapping.CommonControllerMapping; 7 | 8 | public class NHVersionController { 9 | public static int calcu(int param,String version){ 10 | Map paramMap=new HashMap(); 11 | paramMap.put("version", version); 12 | paramMap.put("param", param); 13 | Map retMap=CommonControllerMapping.execVersionMapping("NHVersionController","calcu", version, paramMap); 14 | Integer retInt=(Integer) retMap.get("retInt"); 15 | return retInt; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/NoNHVersionController.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller; 2 | 3 | public class NoNHVersionController { 4 | public static int calcu(int param,String version){ 5 | if(version.equals("v1_0_1")){ 6 | System.out.println("this is nonhversioin v1_0_1"); 7 | return param+1; 8 | }else if(version.equals("v1_0_5")){ 9 | System.out.println("this is nonhversion v1_0_5"); 10 | return param+5; 11 | }else if(version.equals("v1_1_0")){ 12 | System.out.println("this is nonhversion v1_1_0"); 13 | return param+10; 14 | } 15 | System.out.println("this is nonhversion not catch"); 16 | return 0; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd1.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | 10 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_0_0",beanId="cmd1") 11 | public class CalcuCmd1 extends IControllerCommand{ 12 | 13 | @Override 14 | public Map execute(Map paramMap) { 15 | System.out.println("this is nhversion v1_0_0"); 16 | int param=(Integer) paramMap.get("param"); 17 | int ret=param+1; 18 | Map retMap=new HashMap(); 19 | retMap.put("retInt", ret); 20 | return retMap; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd2.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_0_5",beanId="cmd2") 10 | public class CalcuCmd2 extends IControllerCommand{ 11 | 12 | @Override 13 | public Map execute(Map paramMap) { 14 | System.out.println("this is nhversion v1_0_5"); 15 | int param=(Integer) paramMap.get("param"); 16 | int ret=param+5; 17 | Map retMap=new HashMap(); 18 | retMap.put("retInt", ret); 19 | return retMap; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /NHVersionSupportSpringDemo/src/com/jeffreyning/nhversion/demo/controller/cmd/CalcuCmd3.java: -------------------------------------------------------------------------------- 1 | package com.jeffreyning.nhversion.demo.controller.cmd; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.jeffreyning.nhversion.common.version.cmd.IControllerCommand; 7 | import com.jeffreyning.nhversion.common.version.mapping.ControllerMappingAnno; 8 | 9 | @ControllerMappingAnno(controllerName="NHVersionController",funcName="calcu",funcVer="v1_1_0",beanId="cmd3") 10 | public class CalcuCmd3 extends IControllerCommand{ 11 | 12 | @Override 13 | public Map execute(Map paramMap) { 14 | System.out.println("this is nhversion v1_1_0"); 15 | int param=(Integer) paramMap.get("param"); 16 | int ret=param+10; 17 | Map retMap=new HashMap(); 18 | retMap.put("retInt", ret); 19 | return retMap; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/README.md -------------------------------------------------------------------------------- /nhversion-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/nhversion-1.0.jar -------------------------------------------------------------------------------- /nhversion-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeffreyning/NHVersion/03f397ab47de725279a8ef23792d59021abda337/nhversion-1.1.jar --------------------------------------------------------------------------------