您的位置:首页 > 其它

version接口

2015-12-22 17:47 267 查看
发包时候一般需要验证是否正确版本

通过脚本在classes目录下生成一个version.txt文件

并在程序中提供version接口
import java.io.IOException;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.arcsoft.web.openapi.common.basic.BaseController;

@RestController
@RequestMapping("/rest/service/version")
public class VersionController extends BaseController{

@RequestMapping(value = "/versionInfo", method = RequestMethod.GET)
@ResponseBody
public Object versionInfo() throws Exception{
ClassPathResource res = new ClassPathResource("version.txt");
String ret = "unknown, version.txt does not exist!!!";
if(res.exists()){
List<String> retList = null;
try{
retList = IOUtils.readLines(res.getInputStream());
ret = retList.get(0);
}catch(IOException e){
e.printStackTrace();
}
}
return ret;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: