码迷,mamicode.com
首页 > Web开发 > 详细

hibernate 保存空间数据到空间库

时间:2018-01-30 23:11:09      阅读:387      评论:0      收藏:0      [点我收藏+]

标签:mda   fresh   col   tde   gpo   def   class   equals   post   

jsp

<form class="form-horizontal" id="infoForm">
                            <div class="modal-body">
                                <div class="panel-body">
                                    <div class="row">
                                        <input type="hidden" name="gid"  />
                                        <div class="form-group">
                                            <label for="name" class="control-label col-md-3">名称:</label>
                                            <div class="col-md-8">
                                                <input type="text" id="name" name="name" class="form-control "  required/>
                                            </div>
                                            <div class="col-md-1">
                                                <span style="color:red;text-align:center">*</span>
                                            </div>
                                        </div>
                                       
                                        <div class="form-group">
                                            <label for="type" class="control-label col-md-3">基建类型:</label>
                                            <div class="col-md-8">
                                                <select id="type" name="type" class="form-control " >
                                                    <option value=‘‘>请选择基建类型</option>
                                                    <option value=‘瞭望塔‘ >瞭望塔</option>
                                                    <option value=‘通讯塔‘>通讯塔</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group" >
                                            <label class="control-label col-md-3">附件:</label>
                                            <div class="col-md-8" id="imgsContent">
                                            </div>
                                        </div>
                                        <!-- 附件 -->
                                        <div class="form-group">
                                            <label for="fileList" class="control-label col-md-3">附件上传:</label>
                                            <div class="col-md-8">
                                                <input type="file" accept="image/*"  multiple="multiple" id="fileList" name="fileList"  class="form-control " />
                                            </div>
                                        </div>
                                        <input type="hidden" id="imgFile" name="imgPath" class="form-control "/>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <input class="btn btn-success" type="submit" value="保 存" />
                                <input class="btn btn-default" type="reset" value="重 置" />
                            </div>
                        </form>

 

js

$(function(){
            iniTable();
            filter();
            $("#btn_search").click(function(){
                $(‘#mytab‘).bootstrapTable(‘selectPage‘,1);
            });
            $("#infoWindow").on("submit",function(e){
                e.preventDefault();
                var form = new FormData(document.getElementById("infoForm"));
                var url=$("#modalTitle").text()=="新增"?localhostPaht+ctx+‘/resource/observatory/create‘:localhostPaht+ctx+‘/resource/observatory/update‘;
                $.ajax({
                    type: "post",
                    url: url,
                    data: form,
                    dataType: "json",
                    contentType: false,
                    processData: false,
                    success: function(response){
                        $modal.modal(‘hide‘);
                        alert(response.msg);
                        $(‘#mytab‘).bootstrapTable(‘refresh‘);
                    }
                });
            });
        });

 

controller

@RequestMapping(value = "create", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,String> create(@Valid Observatory Observatory, @RequestParam("fileList") CommonsMultipartFile[] files) {
        Map<String,String> maps=new HashMap<String, String>();
        try {
            //img文件上传
            StringBuilder path = new StringBuilder();
            for (CommonsMultipartFile file : files) {
                String url = FtpSftpUtil.fileToFtp(file,folder);
                if (StringUtils.isNoneBlank(url)) {
                    path.append(url).append(";");
                }
            }
            String imgPath=Observatory.getImgPath();
            imgPath=StringUtils.isNoneBlank(Observatory.getImgPath())&&!"null".equals(Observatory.getImgPath())?Observatory.getImgPath()+path.toString():path.toString();
            Observatory.setImgPath(imgPath);
            observatoryService.saveObservatory(Observatory);
            maps.put("msg", MESSAGE_CREATE_SUCCESS);
        } catch (Exception e) {
            LoggerUtil.error(e);
            maps.put("msg", MESSAGE_CREATE_FAIL);
        }
        return maps;
    }

 

service

public void saveObservatory(Observatory entity) {
        Coordinate coord = new Coordinate(entity.getGisx().doubleValue(), entity.getGisy().doubleValue());
        Point point = geometryFactory.createPoint(coord);
        Geometry geom = geometryFactory.createGeometry(point);
        geom.setSRID(2343);
        entity.setGeom(geom);
        observatoryDao.save(entity);
    }

 

hibernate 保存空间数据到空间库

标签:mda   fresh   col   tde   gpo   def   class   equals   post   

原文地址:https://www.cnblogs.com/73tong/p/8387163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!