首页 \ 问答 \ spring数据mongodb _id映射偏好(spring data mongodb _id mapping preference)

spring数据mongodb _id映射偏好(spring data mongodb _id mapping preference)

我在我的Java应用程序中使用弹簧数据mongodb框架来将我的应用程序数据保存在mongodb中。 在我的java模型类中,我有两个字段。

1)一个带有@Id标注的字段。 2)字段ID

关于映射到保存的mongodb文档中的_id键,哪一个会得到首选项,否则我会得到多重映射的错误。 我正在使用弹簧数据mongo 1.6.1。 我知道我可以测试这个,但我没有本地环境设置。


I am using spring data mongodb framework in my java application to persist my application data in mongodb. In my java model class I have two fields.

1) A field objId with @Id annotation on it. 2) A field id

with respect to mapping to _id key in the mongodb document saved, which one will get preference or will I get an error for multiple mapping. I am using spring data mongo 1.6.1. I know I could have tested this out but I do not have local environment setup.


原文:https://stackoverflow.com/questions/27387335
更新时间:2023-10-12 16:10

最满意答案

请参考这个JS小提琴

这个小提琴已经解决了关闭infowindow的所有问题,这是必需的。

JS代码:

var tm;
$(function () {
    //MAP STYLES
    var styledMapType = new google.maps.StyledMapType([{
        featureType: "water",
        elementType: "all",
        stylers: [{
            saturation: 0
        }, {
            lightness: 100
        }]
    }, {
        featureType: "all",
        elementType: "all",
        stylers: [{
            saturation: -100
        }]
    }], {
        name: "white"
    });

    tm = TimeMap.init({
        mapId: "map", // Id of map div element (required)
        timelineId: "timeline", // Id of timeline div element (required) 
        width: 100,
        options: {
            eventIconPath: "",
            theme: "red"
        },
        bandInfo: [{
            width: "75%",
            intervalUnit: Timeline.DateTime.DAY,
            intervalPixels: 215
        }, {
            width: "25%",
            intervalUnit: Timeline.DateTime.MONTH,
            intervalPixels: 125,
            showEventText: false,
            trackHeight: 0.2,
            trackGap: 0.2
        }],

        datasets: [{
            title: "Events",
            id: "events",
            theme: "purple",
            type: "gss",
            options: {
                // note that your spreadsheet must be published for this to work
                //                key: "pjUcDAp-oNIOjmx3LCxT4XA",
                url: "https://spreadsheets.google.com/feeds/list/1elu4weQh25aK01wB5pliKMeST5hiuyxHvKtcSFjBmRc/1/public/values?alt=json-in-script",
                // map spreadsheet column names to expected ids
                paramMap: {
                    start: "date"
                },
                extraColumns: ["Title", "Date",
                    "Date infowindow", "Photo",
                    "Photo bijschrift", "Credit",
                    "Url credit", "Url",
                    "Url tekst"],
                infoTemplate: "<div style='overflow:hidden;line-height:1.35;min-width:200px;'><div id='oorlog-info'><table><tr><td valign='top'><div class='foto'>" +
                    "<img src='{{Photo}}' /> <div class='bijschrift'>" +
                    "<p>{{Photo bijschrift}}<br><a href='{{Url credit}}'>{{Credit}}</a></p></div> </div></td><td valign='top'><div class='data'>" +
                    "<span>{{Date infowindow}}</span><h3>{{Title}}</h3>" +
                    "<p>{{description}}<br /><a href='{{Url}}'>{{Url tekst}}</a></p></div></div><br style='clear: both'"
            }
        }],
        bandIntervals: [
        Timeline.DateTime.WEEK,
        Timeline.DateTime.MONTH]
    });
    var gmap = tm.getNativeMap();
    gmap.mapTypes.set("white", styledMapType);
    gmap.setMapTypeId("white");
});

CSS代码:

#timemap {
    height: 1000px;
}
div#timelinecontainer {
    width: 960px;
    height: 250px;
}
div#timeline {
    width: 960px;
    height: 100%;
    font-size: 11px;
    background: #CCCCCC;
}
div#mapcontainer {
    width: 960px;
    height: 750px;
}
div#map {
    width: 100%;
    height: 100%;
    background: #EEEEEE;
}
div.infodescription {
    font-style: normal;
    width: 300px;
}
#oorlog-info {
    position: relative;
    height: auto
}
#oorlog-info .foto {
    width: 340px;
    position: relative;
    float: left;
}
#oorlog-info .foto > img {
    width: 340px;
}
#oorlog-info .foto .bijschrift {
    background: rgba(0, 0, 0, 0.85);
    position: absolute;
    margin:0 auto;
    bottom: 3px;
    width: 340px;
    margin: 0 0px 0px;
}
#oorlog-info .foto .bijschrift > p {
    color: #fff;
    font-size: 9px;
    line-height: 12px;
    padding: 5px 7px 4px;
    text-transform: uppercase;
}
#oorlog-info .foto .bijschrift > p > a {
    color: #c4c4c4;
    font-size: 9px;
    font-style: italic;
}
#oorlog-info .foto .bijschrift > p > a:hover {
    text-decoration: underline;
}
#oorlog-info .data > span {
    background: #111;
    padding: 5px 8px;
    color: #fff;
    display: inline-block;
    font-size: 11px;
    font-weight: bold;
    margin: 0 0 0 10px;
    float: left;
}
#oorlog-info .data > h3 {
    padding: 0;
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    margin: 6px 0 0 8px;
}
#oorlog-info .data > p {
    padding: 10px;
    font-size: 11px;
    margin: 0;
    width: 295px;
    line-height: 14px;
}
#oorlog-info .data > p > a {
    padding: 10px 0 0;
    display: block;
    text-transform: uppercase;
}
#oorlog-info .data > p > a {
    background-color:#444;
    font-family:'Open Sans', sans-serif;
    font-size:9px;
    text-decoration:none;
    color:#fff;
    margin: 12px 0 0;
    position:relative;
    padding:6px 0px 4px 8px;
    linear, left bottom, left top, color-stop(0, rgb(44, 160, 202)), color-stop(1, rgb(62, 184, 229)));
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    -moz-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    -o-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    width: 150px;
}
#oorlog-info .data > p > a:active {
    top:3px;
    background: #333;
    linear, left bottom, left top, color-stop(0, rgb(62, 184, 229)), color-stop(1, rgb(44, 160, 202)));
    -webkit-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    -moz-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    -o-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
}
#oorlog-info .data > p > a::before {
    background-color:#222;
    background-image:url(http://www.nieuwsblad.be/extra/static/201407_1418/images/right_arrow.png);
    background-repeat:no-repeat;
    background-position:center center;
    content:"";
    width:16px;
    height:16px;
    position:absolute;
    right:9px;
    top:50%;
    margin-top:-7px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    -o-border-radius: 50%;
    border-radius: 50%;
    -webkit-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    -moz-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    -o-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
}
#oorlog-info .data > p > a:active::before {
    top:50%;
    margin-top:-12px;
    -webkit-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    -moz-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    -o-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
}

HTML代码:

<div id="timemap">
    <div id="timelinecontainer">
        <div id="timeline"></div>
    </div>
    <div id="mapcontainer">
        <div id="map"></div>
    </div>
</div>

外部文件添加在小提琴中:

 1. http://timemap.googlecode.com/svn/tags/2.0.1/examples/examples.css
 2. http://maps.google.com/maps?file=api&v=2&key=ABQIAAAASI0kCI-azC8RgbOZzWc3VRRarOQe_TKf_51Omf6UUSOFm7EABRRhO0PO4nBAO9FCmVDuowVwROLo3w
 3. http://timemap.googlecode.com/svn/tags/2.0.1/lib/jquery-1.6.2.min.js
 4. http://timemap.googlecode.com/svn/tags/2.0.1/lib/mxn/mxn.js?(google)
 5. http://timemap.googlecode.com/svn/tags/2.0.1/lib/timeline-1.2.js
 6. http://timemap.googlecode.com/svn/tags/2.0.1/src/timemap.js
 7. http://timemap.googlecode.com/svn/tags/2.0.1/src/param.js
 8. http://timemap.googlecode.com/svn/tags/2.0.1/src/loaders/json.js
 9. http://timemap.googlecode.com/svn/tags/2.0.1/src/loaders/google_spreadsheet.js

如果您有任何其他问题或疑问,请添加您的评论,我可以帮助您解决问题。

问候D.


Please refer to this JS Fiddle

This fiddle is having all the issues solved of closing the infowindow, that was required.

JS Code:

var tm;
$(function () {
    //MAP STYLES
    var styledMapType = new google.maps.StyledMapType([{
        featureType: "water",
        elementType: "all",
        stylers: [{
            saturation: 0
        }, {
            lightness: 100
        }]
    }, {
        featureType: "all",
        elementType: "all",
        stylers: [{
            saturation: -100
        }]
    }], {
        name: "white"
    });

    tm = TimeMap.init({
        mapId: "map", // Id of map div element (required)
        timelineId: "timeline", // Id of timeline div element (required) 
        width: 100,
        options: {
            eventIconPath: "",
            theme: "red"
        },
        bandInfo: [{
            width: "75%",
            intervalUnit: Timeline.DateTime.DAY,
            intervalPixels: 215
        }, {
            width: "25%",
            intervalUnit: Timeline.DateTime.MONTH,
            intervalPixels: 125,
            showEventText: false,
            trackHeight: 0.2,
            trackGap: 0.2
        }],

        datasets: [{
            title: "Events",
            id: "events",
            theme: "purple",
            type: "gss",
            options: {
                // note that your spreadsheet must be published for this to work
                //                key: "pjUcDAp-oNIOjmx3LCxT4XA",
                url: "https://spreadsheets.google.com/feeds/list/1elu4weQh25aK01wB5pliKMeST5hiuyxHvKtcSFjBmRc/1/public/values?alt=json-in-script",
                // map spreadsheet column names to expected ids
                paramMap: {
                    start: "date"
                },
                extraColumns: ["Title", "Date",
                    "Date infowindow", "Photo",
                    "Photo bijschrift", "Credit",
                    "Url credit", "Url",
                    "Url tekst"],
                infoTemplate: "<div style='overflow:hidden;line-height:1.35;min-width:200px;'><div id='oorlog-info'><table><tr><td valign='top'><div class='foto'>" +
                    "<img src='{{Photo}}' /> <div class='bijschrift'>" +
                    "<p>{{Photo bijschrift}}<br><a href='{{Url credit}}'>{{Credit}}</a></p></div> </div></td><td valign='top'><div class='data'>" +
                    "<span>{{Date infowindow}}</span><h3>{{Title}}</h3>" +
                    "<p>{{description}}<br /><a href='{{Url}}'>{{Url tekst}}</a></p></div></div><br style='clear: both'"
            }
        }],
        bandIntervals: [
        Timeline.DateTime.WEEK,
        Timeline.DateTime.MONTH]
    });
    var gmap = tm.getNativeMap();
    gmap.mapTypes.set("white", styledMapType);
    gmap.setMapTypeId("white");
});

CSS Code:

#timemap {
    height: 1000px;
}
div#timelinecontainer {
    width: 960px;
    height: 250px;
}
div#timeline {
    width: 960px;
    height: 100%;
    font-size: 11px;
    background: #CCCCCC;
}
div#mapcontainer {
    width: 960px;
    height: 750px;
}
div#map {
    width: 100%;
    height: 100%;
    background: #EEEEEE;
}
div.infodescription {
    font-style: normal;
    width: 300px;
}
#oorlog-info {
    position: relative;
    height: auto
}
#oorlog-info .foto {
    width: 340px;
    position: relative;
    float: left;
}
#oorlog-info .foto > img {
    width: 340px;
}
#oorlog-info .foto .bijschrift {
    background: rgba(0, 0, 0, 0.85);
    position: absolute;
    margin:0 auto;
    bottom: 3px;
    width: 340px;
    margin: 0 0px 0px;
}
#oorlog-info .foto .bijschrift > p {
    color: #fff;
    font-size: 9px;
    line-height: 12px;
    padding: 5px 7px 4px;
    text-transform: uppercase;
}
#oorlog-info .foto .bijschrift > p > a {
    color: #c4c4c4;
    font-size: 9px;
    font-style: italic;
}
#oorlog-info .foto .bijschrift > p > a:hover {
    text-decoration: underline;
}
#oorlog-info .data > span {
    background: #111;
    padding: 5px 8px;
    color: #fff;
    display: inline-block;
    font-size: 11px;
    font-weight: bold;
    margin: 0 0 0 10px;
    float: left;
}
#oorlog-info .data > h3 {
    padding: 0;
    display: inline-block;
    font-size: 16px;
    font-weight: bold;
    margin: 6px 0 0 8px;
}
#oorlog-info .data > p {
    padding: 10px;
    font-size: 11px;
    margin: 0;
    width: 295px;
    line-height: 14px;
}
#oorlog-info .data > p > a {
    padding: 10px 0 0;
    display: block;
    text-transform: uppercase;
}
#oorlog-info .data > p > a {
    background-color:#444;
    font-family:'Open Sans', sans-serif;
    font-size:9px;
    text-decoration:none;
    color:#fff;
    margin: 12px 0 0;
    position:relative;
    padding:6px 0px 4px 8px;
    linear, left bottom, left top, color-stop(0, rgb(44, 160, 202)), color-stop(1, rgb(62, 184, 229)));
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    -webkit-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    -moz-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    -o-box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    box-shadow: inset 0px 1px 0px #333, 0px 3px 0px 0px #000;
    width: 150px;
}
#oorlog-info .data > p > a:active {
    top:3px;
    background: #333;
    linear, left bottom, left top, color-stop(0, rgb(62, 184, 229)), color-stop(1, rgb(44, 160, 202)));
    -webkit-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    -moz-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    -o-box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
    box-shadow: inset 0px 1px 0px #222, 0px 2px 0px 0px #111, 0px 5px 3px #999;
}
#oorlog-info .data > p > a::before {
    background-color:#222;
    background-image:url(http://www.nieuwsblad.be/extra/static/201407_1418/images/right_arrow.png);
    background-repeat:no-repeat;
    background-position:center center;
    content:"";
    width:16px;
    height:16px;
    position:absolute;
    right:9px;
    top:50%;
    margin-top:-7px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    -o-border-radius: 50%;
    border-radius: 50%;
    -webkit-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    -moz-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    -o-box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
    box-shadow: inset 0px 1px 0px #000, 0px 1px 0px #666;
}
#oorlog-info .data > p > a:active::before {
    top:50%;
    margin-top:-12px;
    -webkit-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    -moz-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    -o-box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
    box-shadow: inset 0px 1px 0px #666, 0px 2px 0px #444, 0px 4px 3px #111;
}

HTML Code:

<div id="timemap">
    <div id="timelinecontainer">
        <div id="timeline"></div>
    </div>
    <div id="mapcontainer">
        <div id="map"></div>
    </div>
</div>

External Files added in the fiddle:

 1. http://timemap.googlecode.com/svn/tags/2.0.1/examples/examples.css
 2. http://maps.google.com/maps?file=api&v=2&key=ABQIAAAASI0kCI-azC8RgbOZzWc3VRRarOQe_TKf_51Omf6UUSOFm7EABRRhO0PO4nBAO9FCmVDuowVwROLo3w
 3. http://timemap.googlecode.com/svn/tags/2.0.1/lib/jquery-1.6.2.min.js
 4. http://timemap.googlecode.com/svn/tags/2.0.1/lib/mxn/mxn.js?(google)
 5. http://timemap.googlecode.com/svn/tags/2.0.1/lib/timeline-1.2.js
 6. http://timemap.googlecode.com/svn/tags/2.0.1/src/timemap.js
 7. http://timemap.googlecode.com/svn/tags/2.0.1/src/param.js
 8. http://timemap.googlecode.com/svn/tags/2.0.1/src/loaders/json.js
 9. http://timemap.googlecode.com/svn/tags/2.0.1/src/loaders/google_spreadsheet.js

If you have any other concern or query, please add your comment, and I can help you out to solve it.

Regards D.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)