hibernate 保存空间数据到空间库


jsp

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 create(@Valid Observatory Observatory, @RequestParam("fileList") CommonsMultipartFile[] files) {
        Map maps=new HashMap();
        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);
    }