uploadsingleimage

来源:互联网 发布:周朝放弃关中 知乎 编辑:程序博客网 时间:2024/06/10 14:20
html代码
<section id="content"><section class="vbox"><section class="scrollable padder"><ul class="breadcrumb no-border no-radius b-b b-light pull-in"><li><i class="fa fa-home"></i> 二維碼</li><li>生產二維碼</li></ul><!--正文开始 --><div class="col-sm-12"><section class="panel panel-success"><header class="panel-heading font-bold">生產二維碼</header><div class="panel-body" id="panel-body"><form role="form" action="createQR.do" method="POST"enctype="multipart/form-data"><div class="form-group" style="height: 50px;"></div><div class="form-group"><label>生產二維碼數量</label> <input name="num" value="" type="text"class="form-control" placeholder="请输入生產數量"style="width: auto" /></div><div class="form-group"><label>備註</label> <input name="memo" value="" type="text"class="form-control" placeholder="请输入備註信息"style="width: auto" /></div><div class="form-group"><label>上傳照片</label><input type="file" name="image1"  value=""data-icon="false" id="f1" data-classButton="btn btn-default" class="form-control"placeholder="點擊選擇圖片"data-classInput="form-control inline input-s" style="width: auto"onchange="changeImg1()"/> <input id="imgNumber1" name="imgNumber1" value='' style="display: none" /><input id="flag" name="flag" value='' style="display: none" />    <input id="imgNumber1" name="imgNumber1" value='' style="display: none" />    <input id="style" name="style" value='' style="display: none" /></div><!-- 预览 --><div class="col-sm-10"><label class="col-sm-2 control-label" style="margin-top:20px;">预览</label><div class="row aaaa1" style="position: relative; left: 0px;"></div><div style="height: 200px"></div></div><input type="submit" class="btn btn-sm btn-success" value="生產"><input type="reset" class="btn btn-sm btn-default" value="取消"><div style="height: 100px"></div></form></div></section></div></section></section></section>

java代码

/** * 生产二维码 *  * @param request * @param modelMap * @return * @throws Exception */@RequestMapping("/createQR.do")public ModelAndView createQR(HttpServletRequest request, ModelMap modelMap,@RequestParam MultipartFile image1) throws Exception {String imagePath;String memo = request.getParameter("memo");final String num = request.getParameter("num");String imgNumber1 = getParameterCheck(request, "imgNumber1");// 接收图片int count = Integer.valueOf(num);String imageRelativePath1 = new String();if (null != imgNumber1) {if (null == image1.getContentType()|| image1.getContentType().split("/") == null) {imageRelativePath1 = String.valueOf(System.currentTimeMillis())+ ".jpg";//} else {if (image1.getContentType().split("/").length > 1) {imageRelativePath1 = String.valueOf(System.currentTimeMillis())+ "."+ image1.getContentType().split("/")[1];//} else {imageRelativePath1 = String.valueOf(System.currentTimeMillis()) + ".jpg";//}}imagePath = IMAGE_FILE + imageRelativePath1;ImageZipUtil.compressPic(image1, imagePath);imageRelativePath1 = IMAGE_PATH + imageRelativePath1;}boolean result = createCode(count, imageRelativePath1, memo);modelMap.put("result", result);return new ModelAndView("html/QRCodeAddsuccess");}private boolean createCode(int count, String imageRelativePath, String memo) {StringBuffer a = new StringBuffer("100000");PetTagDO petTagDO = petTagDAO.getLastCode();if (null == petTagDO) {a.replace(0, 1, "A");String randomCode = getRandomString(3);// 隨機驗證碼PetTagDO petTag = new PetTagDO();petTag.setIdentityNo(a.toString());petTag.setStartCode(randomCode);petTag.setQrStatus("1");petTag.setCreater("0");petTag.setRegisterSign("0");petTag.setMemo(memo);petTag.setImgUrl(imageRelativePath);petTagDAO.createCode(petTag);StringBuffer firstStr = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ");char first = a.charAt(0);// 获取最后一条code 的第一个字符a.replace(0, 1, "1");// 替换第一个字符,成为纯数字的字符串int tempNo = Integer.parseInt(a.toString());// 转为intfor (int i = 0; i < count - 1; i++) {tempNo++;if (tempNo == 200000) {int index = firstStr.indexOf(String.valueOf(first));// 获取原来第一个字符在定义的firstStr的indexchar next = firstStr.charAt(index + 1);// 取得下一个字母first = next;tempNo = 100000;StringBuffer existNo = new StringBuffer(String.valueOf(tempNo));existNo.replace(0, 1, String.valueOf(next));//randomCode = getRandomString(3);// 隨機驗證碼PetTagDO petTagNext = new PetTagDO();petTagNext.setIdentityNo(existNo.toString());petTagNext.setStartCode(randomCode);petTagNext.setQrStatus("1");petTagNext.setCreater("0");petTagNext.setRegisterSign("0");petTagNext.setImgUrl(imageRelativePath);petTagNext.setMemo(memo);// return existNo.toString();} else {StringBuffer existNo = new StringBuffer(String.valueOf(tempNo));existNo.replace(0, 1, String.valueOf(first));//randomCode = getRandomString(3);// 隨機驗證碼PetTagDO petTagNext = new PetTagDO();petTagNext.setIdentityNo(existNo.toString());petTagNext.setStartCode(randomCode);petTagNext.setQrStatus("1");petTagNext.setCreater("0");petTagNext.setRegisterSign("0");petTagNext.setImgUrl(imageRelativePath);petTagNext.setMemo(memo);petTagDAO.createCode(petTagNext);// return existNo.toString();}}} else {StringBuffer existNoOld = new StringBuffer(petTagDO.getIdentityNo());StringBuffer firstStr = new StringBuffer("ABCDEFGHIJKLMNOPQRSTUVWXYZ");char first = existNoOld.charAt(0);// 获取最后一条code 的第一个字符existNoOld.replace(0, 1, "1");// 替换第一个字符,成为纯数字的字符串int tempNo = Integer.parseInt(existNoOld.toString());// 转为intfor (int j = 0; j < count; j++) {tempNo++;if (tempNo == 200000) {int index = firstStr.indexOf(String.valueOf(first));// 获取原来第一个字符在定义的firstStr的indexchar next = firstStr.charAt(index + 1);// 取得下一个字母first = next;tempNo = 100000;StringBuffer existNo = new StringBuffer(String.valueOf(tempNo));existNo.replace(0, 1, String.valueOf(next));//String randomCode = getRandomString(3);// 隨機驗證碼PetTagDO petTag = new PetTagDO();petTag.setIdentityNo(existNo.toString());petTag.setStartCode(randomCode);petTag.setQrStatus("1");petTag.setCreater("0");petTag.setRegisterSign("0");petTag.setImgUrl(imageRelativePath);petTag.setMemo(memo);petTagDAO.createCode(petTag);// return existNo.toString();} else {StringBuffer existNo = new StringBuffer(String.valueOf(tempNo));existNo.replace(0, 1, String.valueOf(first));//String randomCode = getRandomString(3);// 隨機驗證碼PetTagDO petTag = new PetTagDO();petTag.setIdentityNo(existNo.toString());petTag.setStartCode(randomCode);petTag.setQrStatus("1");petTag.setCreater("0");petTag.setRegisterSign("0");petTag.setImgUrl(imageRelativePath);petTag.setMemo(memo);petTagDAO.createCode(petTag);// return existNo.toString();}}return true;}return true;}
js代码
<script type="text/javascript">function changeImg1() {$('.aaaa1').html('')var pic, file;pic = document.getElementById("preview1");file = document.getElementById("f1");var ext = file.value.substring(file.value.lastIndexOf(".") + 1).toLowerCase();// gif在IE浏览器暂时无法显示if (ext != 'png' && ext != 'jpg' && ext != 'jpeg') {alert("图片的格式必须为png或者jpg或者jpeg格式!");return;}var isIE = navigator.userAgent.match(/MSIE/) != null, isIE6 = navigator.userAgent.match(/MSIE 6.0/) != null;if (isIE) {file.select();var reallocalpath = document.selection.createRange().text;// IE6浏览器设置img的src为本地路径可以直接显示图片if (isIE6) {pic.src = reallocalpath;} else {// 非IE6版本的IE由于安全问题直接设置img的src无法显示本地图片,但是可以通过滤镜来实现pic.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image',src=\""+ reallocalpath + "\")";// 设置img的src为base64编码的透明图片 取消显示浏览器默认图片pic.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';}} else {html5Reader1(file);}}function html5Reader1(file) {var index = file.files.length$('#imgNumber1').val(index)for (var i = 0; i < file.files.length; i++) {var f = file.files[i];var reader = new FileReader();reader.readAsDataURL(f);reader.onload = function(e) {var teet = '<div> <img id="preview1" name="pic"style=" height: 200px; float: left; position: relative;margin: 1px 1px " src=' + this.result + '><div>'$('.aaaa1').append(teet)}}}</script>

.properties文件

run_mode=DEVapp_name=jiumelogging_root=/home/logs/jiumesys_loggingLevel=DEBUGsys_loggingLevel_info=DEBUGsys_logging_encoding=UTF-8jiume_htdocs=E:/eclipse workplace/onway/jiume/htdocscore_protocol=httpcore_web_port=5008ace_service_url= http://xxx.xx.xx.xxx:8080jiume_post_upload_image= C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps_update/jiume/WEB-INF/classes/htdocs/templates/img/jiume_post_image=http://localhost:8080/jiumemng/img/#settlecore_service_url= http://xxx.xx.xxx.xxx:8083#account_service_url=http://xxx.xx.xx.xxx:8083#gotone_service_url = http://xxx.xx.xxx.xxx:8082


0 0
原创粉丝点击