﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-guanxf</title><link>http://www.blogjava.net/17learning/</link><description>我的博客：http://blog.sina.com.cn/17learning</description><language>zh-cn</language><lastBuildDate>Tue, 28 Apr 2026 12:21:36 GMT</lastBuildDate><pubDate>Tue, 28 Apr 2026 12:21:36 GMT</pubDate><ttl>60</ttl><item><title>递归构建树</title><link>http://www.blogjava.net/17learning/archive/2020/09/07/435656.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Mon, 07 Sep 2020 01:56:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2020/09/07/435656.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/435656.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2020/09/07/435656.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/435656.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/435656.html</trackback:ping><description><![CDATA[<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Consolas';font-size:10.5pt;"><span style="color:#808080;"><br /></span><pre style="font-family: Consolas; font-size: 10.5pt;">createTree(<span style="color:#6897bb;">1</span><span style="color:#cc7832;">, </span>orgNodeTree<span style="color:#cc7832;">, </span>sameOrgNodes<span style="color:#cc7832;">, </span><span style="color:#6897bb;">0</span>)<span style="color:#cc7832;">;</span></pre><span style="color:#808080;"><br /><br /></span><pre style="font-family: Consolas; font-size: 10.5pt;"><span style="color:#bbb529;">@NoArgsConstructor<br /></span><span style="color:#bbb529;">@AllArgsConstructor<br /></span><span style="color:#bbb529;">@Getter<br /></span><span style="color:#bbb529;">@Setter<br /></span><span style="color:#cc7832;">public class </span>NodeTree {<br />    <span style="color:#cc7832;">private  </span>String <span style="color:#9876aa;">pName</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">    private  </span>String <span style="color:#9876aa;">name</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">    private  int </span><span style="color:#9876aa;">level</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">    private </span>List&lt;NodeTree&gt; <span style="color:#9876aa;">children</span><span style="color:#cc7832;">;<br /></span>}</pre><span style="color: #808080;"><br />private void createTree(int leave, int ind, Map&lt;String, NodeTree&gt; pIndexNodeNameMap, List&lt;NodeVo&gt; childNodes) {<br /></span><span style="color:#808080;">     Map&lt;String, NodeTree&gt; cIndexNodeNameMap = new HashMap();<br /></span><span style="color:#808080;">     //</span><span style="color:#808080;font-family:'Arial Unicode MS';">构建树</span><span style="color:#808080;"><br /></span><span style="color:#808080;">     int treeNo = pIndexNodeNameMap.size();<br /></span><span style="color:#808080;">     if (treeNo == 0) {<br /></span><span style="color:#808080;">         return;<br /></span><span style="color:#808080;">     }<br /></span><span style="color:#808080;">     int group = 0;<br /></span><span style="color:#808080;">     for (int i = ind; i &lt; childNodes.size(); i++) {<br /></span><span style="color:#808080;">         NodeVo node = childNodes.get(i);<br /></span><span style="color:#808080;">         long index = node.getId() % treeNo;<br /></span><span style="color:#808080;">         NodeTree pNode = pIndexNodeNameMap.get(index + "");<br /></span><span style="color:#808080;">         List&lt;NodeTree&gt; children = pNode.getChildren();<br /></span><span style="color:#808080;">         if (CollectionUtils.isEmpty(children)) {<br /></span><span style="color:#808080;">             children = new ArrayList();<br /></span><span style="color:#808080;">         }<br /></span><span style="color:#808080;">         if (children.size() &gt; 2) {<br /></span><span style="color:#808080;">             leave++;<br /></span><span style="color:#808080;">             createTree(leave, i, cIndexNodeNameMap, childNodes);<br /></span><span style="color:#808080;">             break;<br /></span><span style="color:#808080;">         } else {<br /></span><span style="color:#808080;">             NodeTree child = new NodeTree();<br /></span><span style="color:#808080;">             child.setLevel(leave);<br /></span><span style="color:#808080;">             child.setPName(pNode.getName());<br /></span><span style="color:#808080;">             child.setName(node.getNodeName());<br /></span><span style="color:#808080;">             children.add(child);<br /></span><span style="color:#808080;">             pNode.setChildren(children);<br /></span><span style="color:#808080;">             cIndexNodeNameMap.put(group + "", child);<br /></span><span style="color:#808080;">             group++;<br /></span><span style="color:#808080;">         }<br /></span><span style="color:#808080;">     }<br /></span><span style="color:#808080;"> }<br /><br /><br /></span><pre style="font-family: Consolas; font-size: 10.5pt;"><span style="color:#cc7832;">private boolean </span><span style="color:#ffc66d;">createTree</span>(<span style="color:#cc7832;">int </span>level<span style="color:#cc7832;">, </span>List&lt;NodeTree&gt; parentNodes<span style="color:#cc7832;">, </span>List&lt;NodeVo&gt; childNodes<span style="color:#cc7832;">, int </span>beginIndex) {<br />    <span style="color:#808080;">//</span><span style="color:#808080;font-family:'Arial Unicode MS';">构建树<br /></span><span style="color:#808080;font-family:'Arial Unicode MS';">    </span>List&lt;NodeTree&gt; nextLevelNodes = <span style="color:#cc7832;">new </span>ArrayList&lt;&gt;()<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">    for </span>(<span style="color:#cc7832;">int </span>i = beginIndex<span style="color:#cc7832;">; </span>i &lt; childNodes.size()<span style="color:#cc7832;">; </span>i++) {<br />        <span style="color:#cc7832;">int </span>parentCount = <span style="color:#6897bb;">1</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">        for </span>(NodeTree pNode : parentNodes) {<br />            List&lt;NodeTree&gt; children = pNode.getChildren()<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">            if </span>(CollectionUtils.<span style="font-style:italic;">isEmpty</span>(children)) {<br />                children = <span style="color:#cc7832;">new </span>ArrayList()<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>pNode.setChildren(children)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">            </span>}<br />            <span style="color:#cc7832;">if </span>(children.size() &gt;= <span style="color:#6897bb;">3</span>) {<br />                <span style="color:#cc7832;">if</span>(parentCount &gt;= parentNodes.size()){<br />                    <span style="color:#cc7832;">return </span>createTree(++level<span style="color:#cc7832;">, </span>nextLevelNodes<span style="color:#cc7832;">, </span>childNodes<span style="color:#cc7832;">, </span>beginIndex)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>}<br />            } <span style="color:#cc7832;">else </span>{<br />                <span style="color:#cc7832;">if </span>(beginIndex &gt;= childNodes.size()) {<br />                    <span style="color:#cc7832;">return true;<br /></span><span style="color:#cc7832;">                </span>}<br />                NodeTree child = <span style="color:#cc7832;">new </span>NodeTree()<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>child.setLevel(level)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>child.setPName(pNode.getName())<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>NodeVo node = childNodes.get(beginIndex)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>child.setName(node.getNodeName())<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>pNode.getChildren().add(child)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>nextLevelNodes.add(child)<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">                </span>beginIndex++<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">            </span>}<br />            parentCount++<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">        </span>}<br />    }<br />    <span style="color:#cc7832;">return true;<br /></span>}</pre></pre><img src ="http://www.blogjava.net/17learning/aggbug/435656.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2020-09-07 09:56 <a href="http://www.blogjava.net/17learning/archive/2020/09/07/435656.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Push rejected: Push to origin/master was rejected</title><link>http://www.blogjava.net/17learning/archive/2018/05/20/433224.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Sun, 20 May 2018 04:30:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2018/05/20/433224.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/433224.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2018/05/20/433224.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/433224.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/433224.html</trackback:ping><description><![CDATA[<div>执行命名：<br />git pull github master --allow-unrelated-histories<br /><br />执行结果如下：<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->E:\WorkSpace\workspaceJ2ee\abocode\jfaster&gt;git&nbsp;pull&nbsp;github&nbsp;master&nbsp;--allow-unrelated-histories<br />remote:&nbsp;Counting&nbsp;objects:&nbsp;3,&nbsp;done.<br />remote:&nbsp;Total&nbsp;3&nbsp;(delta&nbsp;0),&nbsp;reused&nbsp;0&nbsp;(delta&nbsp;0),&nbsp;pack-reused&nbsp;3<br />Unpacking&nbsp;objects:&nbsp;100%&nbsp;(3/3),&nbsp;done.<br />From&nbsp;https:<span style="color: #008000; ">//</span><span style="color: #008000; ">github.com/abocode/jfaster</span><span style="color: #008000; "><br /></span>&nbsp;*&nbsp;branch&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;master&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt;&nbsp;FETCH_HEAD<br />&nbsp;*&nbsp;[<span style="color: #0000FF; ">new</span>&nbsp;branch]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;master&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&gt;&nbsp;github/master<br />Merge&nbsp;made&nbsp;by&nbsp;the&nbsp;'recursive'&nbsp;strategy.<br />&nbsp;.gitattributes&nbsp;|&nbsp;3&nbsp;+++<br />&nbsp;1&nbsp;file&nbsp;changed,&nbsp;3&nbsp;insertions(+)<br />&nbsp;create&nbsp;mode&nbsp;100644&nbsp;.gitattributes</div></div><img src ="http://www.blogjava.net/17learning/aggbug/433224.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2018-05-20 12:30 <a href="http://www.blogjava.net/17learning/archive/2018/05/20/433224.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Idea Github设置远程Remote仓库时显示authentication failed for xxx错误</title><link>http://www.blogjava.net/17learning/archive/2018/05/20/433223.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Sun, 20 May 2018 04:29:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2018/05/20/433223.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/433223.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2018/05/20/433223.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/433223.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/433223.html</trackback:ping><description><![CDATA[<p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; text-align: justify; word-break: break-all; font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; background-color: #ffffff;">进入&#8220;控制面板&#8221;&#8212;&#8212;&#8220;用户账户&#8221;-凭据管理器&#8212;&#8212;windows凭据</p><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; text-align: justify; word-break: break-all; font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun; background-color: #ffffff;">找到了git的用户名密码。修改正确后ok</p><div><img src="https://img-blog.csdn.net/20170704204018659?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbXpxcXFxcQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast"  alt="" /></div><img src ="http://www.blogjava.net/17learning/aggbug/433223.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2018-05-20 12:29 <a href="http://www.blogjava.net/17learning/archive/2018/05/20/433223.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java自定义注解简单入门</title><link>http://www.blogjava.net/17learning/archive/2016/08/18/431631.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Thu, 18 Aug 2016 12:42:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2016/08/18/431631.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/431631.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2016/08/18/431631.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/431631.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/431631.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; line-height: 24px; background-color: #ffffff;"><strong style="margin: 0px; padding: 0px;">元注解：</strong></p><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; line-height: 24px; background-color: #ffffff;">　　元注解的作用就是负责注解其他注解。Java5.0定义了4个标准的meta-annotation类型，它们被用来提供对其它 annotation类型作说明。Java5.0定义的元注解：<br style="margin: 0px; padding: 0px;" />　　　　1.@Target,<br style="margin: 0px; padding: 0px;" />　　　　2.@Retention,<br style="margin: 0px; padding: 0px;" />　　　　3.@Documented,<br style="margin: 0px; padding: 0px;" />　　　　4.@Inherited<br style="margin: 0px; padding: 0px;" /></p><span style="color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.3333px; line-height: 24px; background-color: #ffffff;">　　这些类型和它们所支持的类在java.lang.annotation包中可以找到。下面我们看一下每个元注解的作用和相应分参数的使用说明。</span><br /><strong>以下为一个简单场景的应用：</strong><br />&nbsp;1.定义注解：<br />&nbsp; &nbsp;<br /><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9.8pt;"><span style="color:#bbb529;">@Target</span>(<span style="color:#9876aa;font-style:italic;">TYPE</span>)<br /><span style="color:#bbb529;">@Retention</span>(<span style="color:#9876aa;font-style:italic;">RUNTIME</span>)<br /><span style="color:#cc7832;">public </span>@<span style="color:#cc7832;">interface </span><span style="color:#bbb529;">Table </span>{<br />    <span style="color:#629755;font-style:italic;">/**<br /></span><span style="color:#629755;font-style:italic;">     * (Optional) The name of the table.<br /></span><span style="color:#629755;font-style:italic;">     * </span><span style="color:#77b767;font-style:italic;">&lt;p/&gt;<br /></span> <span style="color:#629755;font-style:italic;">* Defaults to the entity name.<br /></span><span style="color:#629755;font-style:italic;">     */<br /></span> String <span style="color:#ffc66d;">name</span>() <span style="color:#cc7832;">default </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">;<br />}<br /></span></pre><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9.8pt;"><span style="color:#bbb529;">@Target</span>({<span style="color:#9876aa;font-style:italic;">METHOD</span><span style="color:#cc7832;">, </span><span style="color:#9876aa;font-style:italic;">FIELD</span>})<br /><span style="color:#bbb529;">@Retention</span>(<span style="color:#9876aa;font-style:italic;">RUNTIME</span>)<br /><span style="color:#cc7832;">public </span>@<span style="color:#cc7832;">interface </span><span style="color:#bbb529;">Column </span>{<br /><br />    <span style="color:#629755;font-style:italic;">/**<br /></span><span style="color:#629755;font-style:italic;">     * (Optional) The name of the column. Defaults to<br /></span><span style="color:#629755;font-style:italic;">     * the property or field name.<br /></span><span style="color:#629755;font-style:italic;">     */<br /></span> String <span style="color:#ffc66d;">name</span>() <span style="color:#cc7832;">default </span><span style="color:#6a8759;">""</span><span style="color:#cc7832;">;<br />}<br /></span></pre>2、定义实体类：<br />&nbsp;&nbsp;<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9.8pt;"><br /><span style="color:#bbb529;">@Table</span>(<span style="color:#d0d0ff;">name </span>= <span style="color:#6a8759;">"t_s_user"</span>)<br /><span style="color:#cc7832;">public class </span>User {<br />    <span style="color:#bbb529;">@Column</span>(<span style="color:#d0d0ff;">name</span>=<span style="color:#6a8759;">"name"</span>)<br />    <span style="color:#cc7832;">private </span>String <span style="color:#9876aa;">name</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;"><br /></span> <span style="color:#bbb529;">@Column</span>(<span style="color:#d0d0ff;">name</span>=<span style="color:#6a8759;">"pwd"</span>)<br />    <span style="color:#cc7832;">private </span>String <span style="color:#9876aa;">pwd</span><span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;"><br /></span><span style="color:#cc7832;">    public </span>String <span style="color:#ffc66d;">getName</span>() {<br />        <span style="color:#cc7832;">return </span><span style="color:#9876aa;">name</span><span style="color:#cc7832;">;<br /></span> }<br /><br />    <span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">setName</span>(String name) {<br />        <span style="color:#cc7832;">this</span>.<span style="color:#9876aa;">name </span>= name<span style="color:#cc7832;">;<br /></span> }<br /><br />    <span style="color:#cc7832;">public </span>String <span style="color:#ffc66d;">getPwd</span>() {<br />        <span style="color:#cc7832;">return </span><span style="color:#9876aa;">pwd</span><span style="color:#cc7832;">;<br /></span> }<br /><br />    <span style="color:#cc7832;">public void </span><span style="color:#ffc66d;">setPwd</span>(String pwd) {<br />        <span style="color:#cc7832;">this</span>.<span style="color:#9876aa;">pwd </span>= pwd<span style="color:#cc7832;">;<br /></span> }<br />}</pre><br />3、运行：<br /><br /><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:9.8pt;"><span style="color:#cc7832;">public static void </span><span style="color:#ffc66d;">print</span>() {<br />  System.<span style="color:#9876aa;font-style:italic;">out</span>.println(<span style="color:#6a8759;">"table's name</span><span style="color:#6a8759;font-family:'宋体';">：</span><span style="color:#6a8759;">" </span>+ User.<span style="color:#cc7832;">class</span>.getAnnotation(<span style="color:#bbb529;">Table</span>.<span style="color:#cc7832;">class</span>).name())<span style="color:#cc7832;">;<br /></span> Field[] fields = User.<span style="color:#cc7832;">class</span>.getDeclaredFields()<span style="color:#cc7832;">;<br /></span><span style="color:#cc7832;">    for </span>(<span style="color:#cc7832;">int </span>i = <span style="color:#6897bb;">0</span><span style="color:#cc7832;">; </span>i &lt; fields.<span style="color:#9876aa;">length</span><span style="color:#cc7832;">; </span>i++) {<br />        Field field = fields[i]<span style="color:#cc7832;">;<br /></span> System.<span style="color:#9876aa;font-style:italic;">out</span>.println(<span style="color:#6a8759;">"field's type:" </span>+ field.getType().getName())<span style="color:#cc7832;">;<br /></span> System.<span style="color:#9876aa;font-style:italic;">out</span>.println(<span style="color:#6a8759;">"field's columnName:" </span>+ field.getAnnotation(<span style="color:#bbb529;">Column</span>.<span style="color:#cc7832;">class</span>).name())<span style="color:#cc7832;">;<br /></span> }<br />}</pre><br />关于注解的详细介绍：http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html<img src ="http://www.blogjava.net/17learning/aggbug/431631.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2016-08-18 20:42 <a href="http://www.blogjava.net/17learning/archive/2016/08/18/431631.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Maven项目配置文件不在resources下，如何使用idea引入配置文件</title><link>http://www.blogjava.net/17learning/archive/2016/04/29/idea_chooese_classpath.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Fri, 29 Apr 2016 07:42:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2016/04/29/idea_chooese_classpath.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/430297.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2016/04/29/idea_chooese_classpath.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/430297.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/430297.html</trackback:ping><description><![CDATA[1.选择：File-&gt;project structure-&gt;libraries<br /><br />2.左上角选择添加，选择添加java（还提供了添加maven项目），然后选择所需要的目录：<br /><br />3.idea 会提示选择添加什么类型的文件，我们是单纯的文件，所以选择classes<br /><br />&nbsp; &nbsp;<br /><br />&nbsp;<img src ="http://www.blogjava.net/17learning/aggbug/430297.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2016-04-29 15:42 <a href="http://www.blogjava.net/17learning/archive/2016/04/29/idea_chooese_classpath.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>nginx 反向代理到 server</title><link>http://www.blogjava.net/17learning/archive/2016/01/19/429116.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Tue, 19 Jan 2016 09:46:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2016/01/19/429116.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/429116.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2016/01/19/429116.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/429116.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/429116.html</trackback:ping><description><![CDATA[<div>nginx 反向代理到 apache<br /><div>server {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; listen &nbsp; &nbsp; &nbsp; 80;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; server_name &nbsp;app.haeee.com;</div><div><span style="white-space:pre">		</span>index index.html index.htm index.php;</div><div><span style="white-space:pre">	</span> &nbsp; &nbsp;root /alidata/www/movie-app;</div><div><span style="white-space:pre">		</span></div><div>&nbsp; &nbsp; &nbsp;error_page 404 500 502 503 504 http://app.haeee.com;&nbsp;</div><div><span style="white-space:pre">		</span></div><div><span style="white-space:pre">	</span>location ~ .*\.(php|php5)?$</div><div><span style="white-space:pre">	</span>{</div><div></div><div><span style="white-space:pre">		</span>#fastcgi_pass &nbsp;unix:/tmp/php-cgi.sock;</div><div><span style="white-space:pre">		</span>fastcgi_pass &nbsp;127.0.0.1:9000;</div><div><span style="white-space:pre">		</span>fastcgi_index index.php;</div><div><span style="white-space:pre">		</span>include fastcgi.conf;</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>expires 30d;</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>location ~ .*\.(js|css)?$</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>expires 1h;</div><div><span style="white-space:pre">	</span>}</div><div></div><div><span style="white-space:pre">	</span>#伪静态规则</div><div><span style="white-space:pre">	</span>#include /alidata/server/nginx/conf/rewrite/phpwind.conf;</div><div><span style="white-space:pre">	</span>access_log &nbsp;/alidata/log/nginx/access/movie-app.log;</div><div>}</div><br />nginx 反向代理到 tomcat<br />server {</div><div>&nbsp; &nbsp; listen &nbsp; 80;</div><div>&nbsp; &nbsp; server_name &nbsp;hulasou.com www.hulasou.com;</div><div><span style="white-space:pre">	</span>index index.html index.htm index.jsp;<span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>#location ~ .*\.(jsp)?$</div><div><span style="white-space:pre">	</span>location /{<span style="white-space:pre">	</span> &nbsp; &nbsp;<span style="white-space:pre">	</span> &nbsp;</div><div><span style="white-space:pre">		</span>index index.jsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; proxy_pass http://localhost:8181;</div><div><span style="white-space:pre">	</span>}<span style="white-space:pre">	</span></div><div><span style="white-space:pre">	</span>#伪静态规则<span style="white-space: pre;">	</span></div><div><span style="white-space:pre">	</span>include /alidata/server/nginx/conf/rewrite/uuxiaohua.conf;</div><div><span style="white-space:pre">	</span>access_log &nbsp;/alidata/log/nginx/access/uuxiaohua.log;</div><div>}</div><img src ="http://www.blogjava.net/17learning/aggbug/429116.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2016-01-19 17:46 <a href="http://www.blogjava.net/17learning/archive/2016/01/19/429116.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring boot项目打成war包部署到tomcat</title><link>http://www.blogjava.net/17learning/archive/2016/01/14/429055.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Thu, 14 Jan 2016 09:21:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2016/01/14/429055.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/429055.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2016/01/14/429055.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/429055.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/429055.html</trackback:ping><description><![CDATA[1、修改启动项：<br /><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:14pt;"><span style="color:#bbb529;">@SpringBootApplication<br /></span><span style="color:#bbb529;">@ComponentScan<br /></span><span style="color:#bbb529;">@Import</span>({DBConfiguration.<span style="color:#cc7832;">class, </span>ResourceConfiguration.<span style="color:#cc7832;">class,</span>AppConfiguration.<span style="color:#cc7832;">class</span>})<br /><span style="color:#cc7832;">public class </span>Application <span style="color:#cc7832;">extends </span>SpringBootServletInitializer {<br />    <span style="color:#bbb529;">@Override<br /></span> <span style="color:#cc7832;">protected </span>SpringApplicationBuilder <span style="color:#ffc66d;">configure</span>(SpringApplicationBuilder application) {<br />        <span style="color:#cc7832;">return </span>application.sources(Application.<span style="color:#cc7832;">class</span>)<span style="color:#cc7832;">;<br /></span> }</pre>2、修改pom文件：<br />&nbsp; &nbsp; 修改<span style="color: #e8bf6a; font-family: 'Courier New'; font-size: 18.6667px;">packaging</span><br />&nbsp; &nbsp;&nbsp;<span style="font-family: 'Courier New'; font-size: 14pt; color: #e8bf6a;">&lt;packaging&gt;</span><span style="color: #a9b7c6; font-family: 'Courier New'; font-size: 14pt; background-color: #2b2b2b;">war</span><span style="font-family: 'Courier New'; font-size: 14pt; color: #e8bf6a;">&lt;/packaging&gt;<br /></span>&nbsp; 加入打包到tomcat的配置：<br /><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Courier New';font-size:14pt;"><span style="color:#e8bf6a;">&lt;dependency&gt;<br /></span><span style="color:#e8bf6a;">           &lt;groupId&gt;</span>org.springframework.boot<span style="color:#e8bf6a;">&lt;/groupId&gt;<br /></span><span style="color:#e8bf6a;">           &lt;artifactId&gt;</span>spring-boot-starter-tomcat<span style="color:#e8bf6a;">&lt;/artifactId&gt;<br /></span><span style="color:#e8bf6a;">           &lt;scope&gt;</span>provided<span style="color:#e8bf6a;">&lt;/scope&gt;<br /></span><span style="color:#e8bf6a;">       &lt;/dependency&gt;<br /></span><span style="color:#e8bf6a;">&lt;dependency&gt;<br /></span><span style="color:#e8bf6a;">   &lt;groupId&gt;</span>org.springframework.boot<span style="color:#e8bf6a;">&lt;/groupId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;artifactId&gt;</span>spring-boot-legacy<span style="color:#e8bf6a;">&lt;/artifactId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;version&gt;</span>1.0.2.RELEASE<span style="color:#e8bf6a;">&lt;/version&gt;<br /></span><span style="color:#e8bf6a;">&lt;/dependency&gt;<br /></span><span style="color:#e8bf6a;"><br /></span><span style="color:#e8bf6a;">&lt;dependency&gt;<br /></span><span style="color:#e8bf6a;">   &lt;groupId&gt;</span>javax.servlet<span style="color:#e8bf6a;">&lt;/groupId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;artifactId&gt;</span>javax.servlet-api<span style="color:#e8bf6a;">&lt;/artifactId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;version&gt;</span>3.0.1<span style="color:#e8bf6a;">&lt;/version&gt;<br /></span><span style="color:#e8bf6a;">&lt;/dependency&gt;<br /></span><span style="color:#e8bf6a;">&lt;dependency&gt;<br /></span><span style="color:#e8bf6a;">   &lt;groupId&gt;</span>javax.servlet<span style="color:#e8bf6a;">&lt;/groupId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;artifactId&gt;</span>javax.servlet-api<span style="color:#e8bf6a;">&lt;/artifactId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;version&gt;</span>3.0.1<span style="color:#e8bf6a;">&lt;/version&gt;<br /></span><span style="color:#e8bf6a;">&lt;/dependency&gt;<br /></span><span style="color:#e8bf6a;"><br /></span><span style="color:#e8bf6a;">&lt;dependency&gt;<br /></span><span style="color:#e8bf6a;">   &lt;groupId&gt;</span>commons-fileupload<span style="color:#e8bf6a;">&lt;/groupId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;artifactId&gt;</span>commons-fileupload<span style="color:#e8bf6a;">&lt;/artifactId&gt;<br /></span><span style="color:#e8bf6a;">   &lt;version&gt;</span>1.3.1<span style="color:#e8bf6a;">&lt;/version&gt;<br /></span><span style="color:#e8bf6a;">&lt;/dependency&gt;</span></pre><br />3、如果不需要<span style="color: #2f2f2f; font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; font-size: 16px; line-height: 27.2px; text-align: justify; background-color: #ffffff;">JMX</span>在application.properties文件中加入配置项：<br /><div>endpoints.jmx.uniqueNames=true<br />或者直接关闭：</div><div>&nbsp;endpoints.jmx.enabled=false</div><img src ="http://www.blogjava.net/17learning/aggbug/429055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2016-01-14 17:21 <a href="http://www.blogjava.net/17learning/archive/2016/01/14/429055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring Data JDBC 详解</title><link>http://www.blogjava.net/17learning/archive/2015/12/28/428853.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Mon, 28 Dec 2015 15:48:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2015/12/28/428853.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/428853.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2015/12/28/428853.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/428853.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/428853.html</trackback:ping><description><![CDATA[spring data 系列一直是开发者追捧的热潮，而官方并未出spring data &nbsp;jdbc，国外一个开发者让我们看到了福音，文档如下供大家共同学习。<br />
<p><a href="#"><img src="https://secure.travis-ci.org/nurkiewicz/spring-data-jdbc-repository.png?branch=master" alt="Build Status" /></a> <a href="#"><img src="https://maven-badges.herokuapp.com/maven-central/com.nurkiewicz.jdbcrepository/jdbcrepository/badge.svg" alt="Maven Central" /></a></p>
<h1><a href="#spring-data-jdbc-generic-dao-implementation" name="spring-data-jdbc-generic-dao-implementation">Spring Data JDBC generic DAO implementation</a></h1>
<p>The purpose of this project is to provide generic, lightweight and easy to use DAO implementation for relational databases based on <a href="#"><code>JdbcTemplate</code></a> from <a href="#">Spring framework</a>, compatible with Spring Data umbrella of projects.</p>
<h2><a href="#design-objectives" name="design-objectives">Design objectives</a></h2>
<ul>
  <li>Lightweight, fast and low-overhead. Only a handful of classes, <strong>no XML, annotations, reflection</strong></li>
  <li><strong>This is not full-blown ORM</strong>. No relationship handling, lazy loading, dirty checking, caching</li>
  <li>CRUD implemented in seconds</li>
  <li>For small applications where JPA is an overkill</li>
  <li>Use when simplicity is needed or when future migration e.g. to JPA is considered</li>
  <li>Minimalistic support for database dialect differences (e.g. transparent paging of results)</li>
</ul>
<h2><a href="#features" name="features">Features</a></h2>
<p>Each DAO provides built-in support for:</p>
<ul>
  <li>Mapping to/from domain objects through <a href="#"><code>RowMapper</code></a> abstraction</li>
  <li>Generated and user-defined primary keys</li>
  <li>Extracting generated key</li>
  <li>Compound (multi-column) primary keys</li>
  <li>Immutable domain objects</li>
  <li>Paging (requesting subset of results)</li>
  <li>Sorting over several columns (database agnostic)</li>
  <li>Optional support for <em>many-to-one</em> relationships</li>
  <li>Supported databases (continuously tested):
    <ul>
      <li>MySQL</li>
      <li>PostgreSQL</li>
      <li>H2</li>
      <li>HSQLDB</li>
      <li>Derby</li>
      <li>MS SQL Server (2008, 2012)</li>
      <li>Oracle 10g / 11g (9i should work too)</li>
      <li>...and most likely many others</li>
    </ul>
  </li>
  <li>Easily extendable to other database dialects via <a href="#"><code>SqlGenerator</code></a> class.</li>
  <li>Easy retrieval of records by ID</li>
</ul>
<h2><a href="#api" name="api">API</a></h2>
<p>Compatible with Spring Data <a href="#"><code>PagingAndSortingRepository</code></a> abstraction, <strong>all these methods are implemented for you</strong>:</p>
<pre><code class="java">public interface PagingAndSortingRepository&lt;T, ID extends Serializable&gt; extends CrudRepository&lt;T, ID&gt; {
 T  save(T entity);
Iterable&lt;T&gt; save(Iterable&lt;? extends T&gt; entities);
 T  findOne(ID id);
boolean exists(ID id);
Iterable&lt;T&gt; findAll();
   long count();
   void delete(ID id);
   void delete(T entity);
   void delete(Iterable&lt;? extends T&gt; entities);
   void deleteAll();
Iterable&lt;T&gt; findAll(Sort sort);
Page&lt;T&gt; findAll(Pageable pageable);
Iterable&lt;T&gt; findAll(Iterable&lt;ID&gt; ids);
}
</code></pre>
<p><code>Pageable</code> and <code>Sort</code> parameters are also fully supported, which means you get <strong>paging and sorting by arbitrary properties for free</strong>. For example say you have <code>userRepository</code> extending <code>PagingAndSortingRepository&lt;User, String&gt;</code> interface (implemented for you by the library) and you request 5th page of <code>USERS</code> table, 10 per page, after applying some sorting:</p>
<pre><code class="java">Page&lt;User&gt; page = userRepository.findAll(
new PageRequest(
5, 10, 
new Sort(
new Order(DESC, "reputation"), 
new Order(ASC, "user_name")
)
)
);
</code></pre>
<p>Spring Data JDBC repository library will translate this call into (PostgreSQL syntax):</p>
<pre><code class="sql">SELECT *
FROM USERS
ORDER BY reputation DESC, user_name ASC
LIMIT 50 OFFSET 10
</code></pre>
<p>...or even (Derby syntax):</p>
<pre><code class="sql">SELECT * FROM (
SELECT ROW_NUMBER() OVER () AS ROW_NUM, t.*
FROM (
SELECT * 
FROM USERS 
ORDER BY reputation DESC, user_name ASC
) AS t
) AS a 
WHERE ROW_NUM BETWEEN 51 AND 60
</code></pre>
<p>No matter which database you use, you'll get <code>Page&lt;User&gt;</code> object in return (you still have to provide <code>RowMapper&lt;User&gt;</code> yourself to translate from <a href="#"><code>ResultSet</code></a> to domain object). If you don't know Spring Data project yet, <a href="#"><code>Page&lt;T&gt;</code></a> is a wonderful abstraction, not only encapsulating <code>List&lt;T&gt;</code>, but also providing metadata such as total number of records, on which page we currently are, etc.</p>
<h2><a href="#reasons-to-use" name="reasons-to-use">Reasons to use</a></h2>
<ul>
  <li>
    <p>You consider migration to JPA or even some NoSQL database in the future.</p>
    <p>Since your code will rely only on methods defined in <a href="#"><code>PagingAndSortingRepository</code></a> and <a href="#"><code>CrudRepository</code></a> from <a href="#">Spring Data Commons</a> umbrella project you are free to switch from <a href="#"><code>JdbcRepository</code></a> implementation (from this project) to: <a href="#"><code>JpaRepository</code></a>, <a href="#"><code>MongoRepository</code></a>, <a href="#"><code>GemfireRepository</code></a> or <a href="#"><code>GraphRepository</code></a>. They all implement the same common API. Of course don't expect that switching from JDBC to JPA or MongoDB will be as simple as switching imported JAR dependencies - but at least you minimize the impact by using same DAO API.</p>
  </li>
  <li>
  <p>You need a fast, simple JDBC wrapper library. JPA or even <a href="#">MyBatis</a> is an overkill</p></li>
  <li>
  <p>You want to have full control over generated SQL if needed</p></li>
  <li>
  <p>You want to work with objects, but don't need lazy loading, relationship handling, multi-level caching, dirty checking... You need <a href="#">CRUD</a> and not much more</p></li>
  <li>
  <p>You want to by <a href="#"><em>DRY</em></a></p></li>
  <li>
  <p>You are already using Spring or maybe even <a href="#"><code>JdbcTemplate</code></a>, but still feel like there is too much manual work</p></li>
  <li>
  <p>You have very few database tables</p></li>
</ul>
<h2><a href="#getting-started" name="getting-started">Getting started</a></h2>
<p>For more examples and working code don't forget to examine <a href="#">project tests</a>.</p>
<h3><a href="#prerequisites" name="prerequisites">Prerequisites</a></h3>
<p>Maven coordinates:</p>
<pre><code class="xml">&lt;dependency&gt;
&lt;groupId&gt;com.nurkiewicz.jdbcrepository&lt;/groupId&gt;
&lt;artifactId&gt;jdbcrepository&lt;/artifactId&gt;
&lt;version&gt;0.4&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>
<p>This project is available under maven central repository.</p>
<p>Alternatively you can <a href="#">download source code as ZIP</a>.</p>
<hr />
<p>In order to start your project must have <code>DataSource</code> bean present and transaction management enabled. Here is a minimal MySQL configuration:</p>
<pre><code class="java">@EnableTransactionManagement
@Configuration
public class MinimalConfig {
@Bean
public PlatformTransactionManager transactionManager() {
return new DataSourceTransactionManager(dataSource());
}
@Bean
public DataSource dataSource() {
MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
ds.setUser("user");
ds.setPassword("secret");
ds.setDatabaseName("db_name");
return ds;
}
}
</code></pre>
<h3><a href="#entity-with-auto-generated-key" name="entity-with-auto-generated-key">Entity with auto-generated key</a></h3>
<p>Say you have a following database table with auto-generated key (MySQL syntax):</p>
<pre><code class="sql">CREATE TABLE COMMENTS (
id INT AUTO_INCREMENT,
user_name varchar(256),
contents varchar(1000),
created_time TIMESTAMP NOT NULL,
PRIMARY KEY (id)
);
</code></pre>
<p>First you need to create domain object <a href="#"><code>User</code></a> mapping to that table (just like in any other ORM):</p>
<pre><code class="java">public class Comment implements Persistable&lt;Integer&gt; {
private Integer id;
private String userName;
private String contents;
private Date createdTime;
@Override
public Integer getId() {
return id;
}
@Override
public boolean isNew() {
return id == null;
}
//getters/setters/constructors/...
}
</code></pre>
<p>Apart from standard Java boilerplate you should notice implementing <a href="#"><code>Persistable&lt;Integer&gt;</code></a> where <code>Integer</code> is the type of primary key. <code>Persistable&lt;T&gt;</code> is an interface coming from Spring Data project and it's the only requirement we place on your domain object.</p>
<p>Finally we are ready to create our <a href="#"><code>CommentRepository</code></a> DAO:</p>
<pre><code class="java">@Repository
public class CommentRepository extends JdbcRepository&lt;Comment, Integer&gt; {
public CommentRepository() {
super(ROW_MAPPER, ROW_UNMAPPER, "COMMENTS");
}
public static final RowMapper&lt;Comment&gt; ROW_MAPPER = //see below
private static final RowUnmapper&lt;Comment&gt; ROW_UNMAPPER = //see below
@Override
protected &lt;S extends Comment&gt; S postCreate(S entity, Number generatedId) {
entity.setId(generatedId.intValue());
return entity;
}
}
</code></pre>
<p>First of all we use <a href="#"><code>@Repository</code></a> annotation to mark DAO bean. It enables persistence exception translation. Also such annotated beans are discovered by CLASSPATH scanning.</p>
<p>As you can see we extend <code>JdbcRepository&lt;Comment, Integer&gt;</code> which is the central class of this library, providing implementations of all <code>PagingAndSortingRepository</code> methods. Its constructor has three required dependencies: <code>RowMapper</code>, <a href="#"><code>RowUnmapper</code></a> and table name. You may also provide ID column name, otherwise default <code>"id"</code> is used.</p>
<p>If you ever used <code>JdbcTemplate</code> from Spring, you should be familiar with <a href="#"><code>RowMapper</code></a> interface. We need to somehow extract columns from <code>ResultSet</code> into an object. After all we don't want to work with raw JDBC results. It's quite straightforward:</p>
<pre><code class="java">public static final RowMapper&lt;Comment&gt; ROW_MAPPER = new RowMapper&lt;Comment&gt;() {
@Override
public Comment mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Comment(
rs.getInt("id"),
rs.getString("user_name"),
rs.getString("contents"),
rs.getTimestamp("created_time")
);
}
};
</code></pre>
<p><code>RowUnmapper</code> comes from this library and it's essentially the opposite of <code>RowMapper</code>: takes an object and turns it into a <code>Map</code>. This map is later used by the library to construct SQL <code>CREATE</code>/<code>UPDATE</code> queries:</p>
<pre><code class="java">private static final RowUnmapper&lt;Comment&gt; ROW_UNMAPPER = new RowUnmapper&lt;Comment&gt;() {
@Override
public Map&lt;String, Object&gt; mapColumns(Comment comment) {
Map&lt;String, Object&gt; mapping = new LinkedHashMap&lt;String, Object&gt;();
mapping.put("id", comment.getId());
mapping.put("user_name", comment.getUserName());
mapping.put("contents", comment.getContents());
mapping.put("created_time", new java.sql.Timestamp(comment.getCreatedTime().getTime()));
return mapping;
}
};
</code></pre>
<p>If you never update your database table (just reading some reference data inserted elsewhere) you may skip <code>RowUnmapper</code> parameter or use <a href="#"><code>MissingRowUnmapper</code></a>.</p>
<p>Last piece of the puzzle is the <code>postCreate()</code> callback method which is called after an object was inserted. You can use it to retrieve generated primary key and update your domain object (or return new one if your domain objects are immutable). If you don't need it, just don't override <code>postCreate()</code>.</p>
<p>Check out <a href="#"><code>JdbcRepositoryGeneratedKeyTest</code></a> for a working code based on this example.</p>
<blockquote>
  <p>By now you might have a feeling that, compared to JPA or Hibernate, there is quite a lot of manual work. However various JPA implementations and other ORM frameworks are notoriously known for introducing significant overhead and manifesting some learning curve. This tiny library intentionally leaves some responsibilities to the user in order to avoid complex mappings, reflection, annotations... all the implicitness that is not always desired.</p>
  <p>This project is not intending to replace mature and stable ORM frameworks. Instead it tries to fill in a niche between raw JDBC and ORM where simplicity and low overhead are key features.</p>
</blockquote>
<h3><a href="#entity-with-manually-assigned-key" name="entity-with-manually-assigned-key">Entity with manually assigned key</a></h3>
<p>In this example we'll see how entities with user-defined primary keys are handled. Let's start from database model:</p>
<pre><code class="java">CREATE TABLE USERS (
user_name varchar(255),
date_of_birth TIMESTAMP NOT NULL,
enabled BIT(1) NOT NULL,
PRIMARY KEY (user_name)
);
</code></pre>
<p>...and <a href="#"><code>User</code></a> domain model:</p>
<pre><code class="java">public class User implements Persistable&lt;String&gt; {
private transient boolean persisted;
private String userName;
private Date dateOfBirth;
private boolean enabled;
@Override
public String getId() {
return userName;
}
@Override
public boolean isNew() {
return !persisted;
}
public void setPersisted(boolean persisted) {
this.persisted = persisted;
}
//getters/setters/constructors/...
}
</code></pre>
<p>Notice that special <code>persisted</code> transient flag was added. Contract of [<code>CrudRepository.save()</code>](<a href="http://static.springsource.org/spring-data/data-commons/docs/current/api/org/springframework/data/repository/CrudRepository.html#save(S)">http://static.springsource.org/spring-data/data-commons/docs/current/api/org/springframework/data/repository/CrudRepository.html#save(S)</a>) from Spring Data project requires that an entity knows whether it was already saved or not (<code>isNew()</code>) method - there are no separate <code>create()</code> and <code>update()</code> methods. Implementing <code>isNew()</code> is simple for auto-generated keys (see <code>Comment</code> above) but in this case we need an extra transient field. If you hate this workaround and you only insert data and never update, you'll get away with return <code>true</code> all the time from <code>isNew()</code>.</p>
<p>And finally our DAO, <a href="#"><code>UserRepository</code></a> bean:</p>
<pre><code class="java">@Repository
public class UserRepository extends JdbcRepository&lt;User, String&gt; {
public UserRepository() {
super(ROW_MAPPER, ROW_UNMAPPER, "USERS", "user_name");
}
public static final RowMapper&lt;User&gt; ROW_MAPPER = //...
public static final RowUnmapper&lt;User&gt; ROW_UNMAPPER = //...
@Override
protected &lt;S extends User&gt; S postUpdate(S entity) {
entity.setPersisted(true);
return entity;
}
@Override
protected &lt;S extends User&gt; S postCreate(S entity, Number generatedId) {
entity.setPersisted(true);
return entity;
}
}
</code></pre>
<p><code>"USERS"</code> and <code>"user_name"</code> parameters designate table name and primary key column name. I'll leave the details of mapper and unmapper (see <a href="#">source code</a>). But please notice <code>postUpdate()</code> and <code>postCreate()</code> methods. They ensure that once object was persisted, <code>persisted</code> flag is set so that subsequent calls to <code>save()</code> will update existing entity rather than trying to reinsert it.</p>
<p>Check out <a href="#"><code>JdbcRepositoryManualKeyTest</code></a> for a working code based on this example.</p>
<h3><a href="#compound-primary-key" name="compound-primary-key">Compound primary key</a></h3>
<p>We also support compound primary keys (primary keys consisting of several columns). Take this table as an example:</p>
<pre><code class="sql">CREATE TABLE BOARDING_PASS (
flight_no VARCHAR(8) NOT NULL,
seq_no INT NOT NULL,
passenger VARCHAR(1000),
seat CHAR(3),
PRIMARY KEY (flight_no, seq_no)
);
</code></pre>
<p>I would like you to notice the type of primary key in <code>Persistable&lt;T&gt;</code>:</p>
<pre><code class="java">public class BoardingPass implements Persistable&lt;Object[]&gt; {
private transient boolean persisted;
private String flightNo;
private int seqNo;
private String passenger;
private String seat;
@Override
public Object[] getId() {
return pk(flightNo, seqNo);
}
@Override
public boolean isNew() {
return !persisted;
}
//getters/setters/constructors/...
}
</code></pre>
<p>Unfortunately library does not support small, immutable value classes encapsulating all ID values in one object (like JPA does with <a href="#"><code>@IdClass</code></a>), so you have to live with <code>Object[]</code> array. Defining DAO class is similar to what we've already seen:</p>
<pre><code class="java">public class BoardingPassRepository extends JdbcRepository&lt;BoardingPass, Object[]&gt; {
public BoardingPassRepository() {
this("BOARDING_PASS");
}
public BoardingPassRepository(String tableName) {
super(MAPPER, UNMAPPER, new TableDescription(tableName, null, "flight_no", "seq_no")
);
}
public static final RowMapper&lt;BoardingPass&gt; ROW_MAPPER = //...
public static final RowUnmapper&lt;BoardingPass&gt; UNMAPPER = //...
}
</code></pre>
<p>Two things to notice: we extend <code>JdbcRepository&lt;BoardingPass, Object[]&gt;</code> and we provide two ID column names just as expected: <code>"flight_no", "seq_no"</code>. We query such DAO by providing both <code>flight_no</code> and <code>seq_no</code> (necessarily in that order) values wrapped by <code>Object[]</code>:</p>
<pre><code class="java">BoardingPass pass = boardingPassRepository.findOne(new Object[] {"FOO-1022", 42});
</code></pre>
<p>No doubts, this is cumbersome in practice, so we provide tiny helper method which you can statically import:</p>
<pre><code class="java">import static com.nurkiewicz.jdbcrepository.JdbcRepository.pk;
//...
BoardingPass foundFlight = boardingPassRepository.findOne(pk("FOO-1022", 42));
</code></pre>
<p>Check out <a href="#"><code>JdbcRepositoryCompoundPkTest</code></a> for a working code based on this example.</p>
<h3><a href="#transactions" name="transactions">Transactions</a></h3>
<p>This library is completely orthogonal to transaction management. Every method of each repository requires running transaction and it's up to you to set it up. Typically you would place <code>@Transactional</code> on service layer (calling DAO beans). I don't recommend <a href="#">placing <code>@Transactional</code> over every DAO bean</a>.</p>
<h2><a href="#caching" name="caching">Caching</a></h2>
<p>Spring Data JDBC repository library is not providing any caching abstraction or support. However adding <code>@Cacheable</code> layer on top of your DAOs or services using <a href="#">caching abstraction in Spring</a> is quite straightforward. See also: <a href="#"><em>@Cacheable overhead in Spring</em></a>.</p>
<h2><a href="#contributions" name="contributions">Contributions</a></h2>
<p>..are always welcome. Don't hesitate to <a href="#">submit bug reports</a> and <a href="#">pull requests</a>.</p>
<h3><a href="#testing" name="testing">Testing</a></h3>
<p>This library is continuously tested using Travis (<a href="#"><img src="https://secure.travis-ci.org/nurkiewicz/spring-data-jdbc-repository.png?branch=master" alt="Build Status" /></a>). Test suite consists of 60+ distinct tests each run against 8 different databases: MySQL, PostgreSQL, H2, HSQLDB and Derby + MS SQL Server and Oracle tests not run as part of CI.</p>
<p>When filling <a href="#">bug reports</a> or submitting new features please try including supporting test cases. Each <a href="#">pull request</a> is automatically tested on a separate branch.</p>
<h3><a href="#building" name="building">Building</a></h3>
<p>After forking the <a href="#">official repository</a> building is as simple as running:</p>
<pre><code class="bash">$ mvn install
</code></pre>
<p>You'll notice plenty of exceptions during JUnit test execution. This is normal. Some of the tests run against MySQL and PostgreSQL available only on Travis CI server. When these database servers are unavailable, whole test is simply <em>skipped</em>:</p>
<pre><code>Results :
Tests run: 484, Failures: 0, Errors: 0, Skipped: 295
</code></pre>
<p>Exception stack traces come from root <a href="#"><code>AbstractIntegrationTest</code></a>.</p>
<h2><a href="#design" name="design">Design</a></h2>
<p>Library consists of only a handful of classes, highlighted in the diagram below (<a href="#">source</a>):</p>
<p><img src="https://raw.github.com/nurkiewicz/spring-data-jdbc-repository/master/src/main/docs/classes.png" alt="UML diagram" /></p>
<p><a href="#"><code>JdbcRepository</code></a> is the most important class that implements all <a href="#"><code>PagingAndSortingRepository</code></a> methods. Each user repository has to extend this class. Also each such repository must at least implement <a href="#"><code>RowMapper</code></a> and <a href="#"><code>RowUnmapper</code></a> (only if you want to modify table data).</p>
<p>SQL generation is delegated to <a href="#"><code>SqlGenerator</code></a>. <a href="#"><code>PostgreSqlGenerator.</code></a> and <a href="#"><code>DerbySqlGenerator</code></a> are provided for databases that don't work with standard generator.</p>
<h2><a href="#changelog" name="changelog">Changelog</a></h2>
<h3><a href="#0-4-1" name="0-4-1">0.4.1</a></h3>
<ul>
  <li>Fixed <a href="#"><em>Standalone Configuration and CDI Implementation</em></a></li>
</ul>
<h3><a href="#0-4" name="0-4">0.4</a></h3>
<ul>
  <li>Repackaged: <code>com.blogspot.nurkiewicz</code> -&gt; <code>com.nurkiewicz</code></li>
</ul>
<h3><a href="#0-3-2" name="0-3-2">0.3.2</a></h3>
<ul>
  <li>First version available in Maven central repository</li>
  <li>Upgraded Spring Data Commons 1.6.1 -&gt; 1.8.0</li>
</ul>
<h3><a href="#0-3-1" name="0-3-1">0.3.1</a></h3>
<ul>
  <li>Upgraded Spring dependencies: 3.2.1 -&gt; 3.2.4 and 1.5.0 -&gt; 1.6.1</li>
  <li>Fixed <a href="#">#5 Allow manually injecting JdbcOperations, SqlGenerator and DataSource</a></li>
</ul>
<h3><a href="#0-3" name="0-3">0.3</a></h3>
<ul>
  <li>Oracle 10g / 11g support (see <a href="#">pull request</a>)</li>
  <li>Upgrading Spring dependency to 3.2.1.RELEASE and <a href="#">Spring Data Commons</a> to 1.5.0.RELEASE (see <a href="#">#4</a>).</li>
</ul>
<h3><a href="#0-2" name="0-2">0.2</a></h3>
<ul>
  <li>MS SQL Server 2008/2012 support (see <a href="#">pull request</a>)</li>
</ul>
<h3><a href="#0-1" name="0-1">0.1</a></h3>
<ul>
  <li>Initial revision (<a href="#">announcement</a>)</li>
</ul>
<h2><a href="#license" name="license">License</a></h2>
<p>This project is released under version 2.0 of the <a href="#">Apache License</a> (same as <a href="#">Spring framework</a>).</p><img src ="http://www.blogjava.net/17learning/aggbug/428853.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2015-12-28 23:48 <a href="http://www.blogjava.net/17learning/archive/2015/12/28/428853.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>IntelliJ IDEA 快捷键大全，及IDEA常用配置</title><link>http://www.blogjava.net/17learning/archive/2015/09/26/hulasou.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Sat, 26 Sep 2015 03:38:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2015/09/26/hulasou.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/427503.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2015/09/26/hulasou.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/427503.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/427503.html</trackback:ping><description><![CDATA[<div><font face="Tahoma, Geneva, 微软雅黑, 宋体"><span style="line-height: 25px;"><strong>Idea是目前最好的开发工具，经收集及整理如下常用快捷键：&nbsp;<br />一、常用快捷键：</strong> &nbsp; <br /><br />&nbsp; &nbsp;<strong> &nbsp;</strong></span></font><span style="font-family: Tahoma, Geneva, 微软雅黑, 宋体; line-height: 25px;"><strong>&nbsp;&nbsp;1.常用操作：</strong></span><br /><font face="Tahoma, Geneva, 微软雅黑, 宋体"><span style="line-height: 25px;">&nbsp; &nbsp; &nbsp; &nbsp;Ctrl+E，可以显示最近编辑的文件列表</span></font></div><div>　　Shift+Click可以关闭文件</div><div>　　Ctrl+[或]可以跳到大括号的开头结尾</div><div>　　Ctrl+Shift+Backspace可以跳转到上次编辑的地方</div><div>　　Ctrl+F12，可以显示当前文件的结构</div><div>　　Ctrl+F7可以查询当前元素在当前文件中的引用，然后按F3可以选择</div><div>　　Ctrl+N，可以快速打开类</div><div>　　Ctrl+Shift+N，可以快速打开文件</div><div>　　Alt+Q可以看到当前方法的声明</div><div>　　Ctrl+W可以选择单词继而语句继而行继而函数</div><div>　　Alt+F1可以将正在编辑的元素在各个面板中定位</div><div>　　Ctrl+P，可以显示参数信息</div><div>　　Ctrl+Shift+Insert可以选择剪贴板内容并插入</div><div>　　Alt+Insert可以生成构造器/Getter/Setter等</div><div>　　Ctrl+Alt+V 可以引入变量。例如把括号内的SQL赋成一个变量</div><div>　　Ctrl+Alt+T可以把代码包在一块内，例如try/catch</div><div>　　Alt+Up and Alt+Down可在方法间快速移动</div><br /><div><strong>　　2. 查询快捷键</strong></div><div>　　CTRL+N 查找类</div><div>　　CTRL+SHIFT+N 查找文件</div><div>　　CTRL+SHIFT+ALT+N 查找类中的方法或变量</div><div>　　CIRL+B 找变量的来源</div><div>　　CTRL+ALT+B 找所有的子类</div><div>　　CTRL+SHIFT+B 找变量的类</div><div>　　CTRL+G 定位行</div><div>　　CTRL+F 在当前窗口查找文本</div><div>　　CTRL+SHIFT+F 在指定窗口查找文本</div><div>　　CTRL+R 在 当前窗口替换文本</div><div>　　CTRL+SHIFT+R 在指定窗口替换文本</div><div>　　ALT+SHIFT+C 查找修改的文件</div><div>　　CTRL+E 最近打开的文件</div><div>　　F3 向下查找关键字出现位置</div><div>　　SHIFT+F3 向上一个关键字出现位置</div><div>　　F4 查找变量来源</div><div>　　CTRL+ALT+F7 选中的字符查找工程出现的地方</div><div>　　CTRL+SHIFT+O 弹出显示查找内容<br /><br /></div><div>　<strong>　3. 自动代码</strong></div><div>　　ALT+回车 导入包,自动修正</div><div>　　CTRL+ALT+L 格式化代码</div><div>　　CTRL+ALT+I 自动缩进</div><div>　　CTRL+ALT+O 优化导入的类和包</div><div>　　ALT+INSERT 生成代码(如GET,SET方法,构造函数等)</div><div>　　CTRL+E 最近更改的代码</div><div>　　CTRL+SHIFT+SPACE 自动补全代码</div><div>　　CTRL+空格 代码提示</div><div>　　CTRL+ALT+SPACE 类名或接口名提示</div><div>　　CTRL+P 方法参数提示</div><div>　　CTRL+J 自动代码</div><div>　　CTRL+ALT+T 把选中的代码放在 TRY{} IF{} ELSE{} 里<br /><br /></div><div>　<strong>　4. 复制快捷方式</strong></div><div>　　CTRL+D 复制行</div><div>　　CTRL+X 剪切,删除行</div><div>　　5. 其他快捷方式</div><div>　　CIRL+U 大小写切换</div><div>　　CTRL+Z 倒退</div><div>　　CTRL+SHIFT+Z 向前</div><div>　　CTRL+ALT+F12 资源管理器打开文件夹</div><div>　　ALT+F1 查找文件所在目录位置</div><div>　　SHIFT+ALT+INSERT 竖编辑模式</div><div>　　CTRL+/ 注释//</div><div>　　CTRL+SHIFT+/ 注释/*...*/</div><div>　　CTRL+W 选中代码，连续按会有其他效果</div><div>　　CTRL+B 快速打开光标处的类或方法</div><div>　　ALT+ &#8592;/&#8594; 切换代码视图</div><div>　　CTRL+ALT &#8592;/&#8594; 返回上次编辑的位置</div><div>　　ALT+ &#8593;/&#8595; 在方法间快速移动定位</div><div>　　SHIFT+F6 重构-重命名</div><div>　　CTRL+H 显示类结构图</div><div>　　CTRL+Q 显示注释文档</div><div>　　ALT+1 快速打开或隐藏工程面板</div><div>　　CTRL+SHIFT+UP/DOWN 代码向上/下移动。</div><div>　　CTRL+UP/DOWN 光标跳转到第一行或最后一行下</div><div>　　ESC 光标返回编辑框</div><div>　　SHIFT+ESC 光标返回编辑框,关闭无用的窗口</div><div>　　F1 帮助千万别按,很卡!</div><div>　　CTRL+F4 非常重要下班都用<br /><br /><strong>二、常用配置：</strong><br /><div>　　1. IDEA内存优化</div><div>　　因机器本身的配置而配置：</div><div>　　\IntelliJ IDEA 8\bin\idea.exe.vmoptions</div><div>　　-----------------------------------------</div><div>　　-Xms64m</div><div>　　-Xmx256m</div><div>　　-XX:MaxPermSize=92m</div><div>　　-ea</div><div>　　-server</div><div>　　-Dsun.awt.keepWorkingSetOnMinimize=true</div></div><p style="margin: 0px; padding: 0px; font-family: Tahoma, Geneva, 微软雅黑, 宋体; line-height: 25px; background-color: #ffffff;"></p><img src ="http://www.blogjava.net/17learning/aggbug/427503.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2015-09-26 11:38 <a href="http://www.blogjava.net/17learning/archive/2015/09/26/hulasou.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongdb 使用linux shell修改数据</title><link>http://www.blogjava.net/17learning/archive/2015/09/22/427431.html</link><dc:creator>管先飞</dc:creator><author>管先飞</author><pubDate>Tue, 22 Sep 2015 11:25:00 GMT</pubDate><guid>http://www.blogjava.net/17learning/archive/2015/09/22/427431.html</guid><wfw:comment>http://www.blogjava.net/17learning/comments/427431.html</wfw:comment><comments>http://www.blogjava.net/17learning/archive/2015/09/22/427431.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/17learning/comments/commentRss/427431.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/17learning/services/trackbacks/427431.html</trackback:ping><description><![CDATA[1、编写脚步：update.js<br />&nbsp; &nbsp; &nbsp;/**<div>&nbsp;* 时间对象的格式化;</div><div>&nbsp;*/</div><div>Date.prototype.format = function(format) {</div><div>&nbsp; &nbsp; /*</div><div>&nbsp; &nbsp; &nbsp;* eg:format="YYYY-MM-dd hh:mm:ss";</div><div>&nbsp; &nbsp; &nbsp;*/</div><div>&nbsp; &nbsp; var o = {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "M+" :this.getMonth() + 1, // month</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "d+" :this.getDate(), // day</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "h+" :this.getHours(), // hour</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "m+" :this.getMinutes(), // minute</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "s+" :this.getSeconds(), // second</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter</div><div>&nbsp; &nbsp; &nbsp; &nbsp; "S" :this.getMilliseconds()</div><div>&nbsp; &nbsp; // millisecond</div><div>&nbsp; &nbsp; }</div><div>&nbsp;</div><div>&nbsp; &nbsp; if (/(y+)/.test(format)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; format = format.replace(RegExp.$1, (this.getFullYear() + "")</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .substr(4 - RegExp.$1.length));</div><div>&nbsp; &nbsp; }</div><div>&nbsp;</div><div>&nbsp; &nbsp; for ( var k in o) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if (new RegExp("(" + k + ")").test(format)) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : ("00" + o[k]).substr(("" + o[k]).length));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; }</div><div>&nbsp; &nbsp; return format;</div><div>}</div><div></div><div></div><div>var date =new Date();</div><div>var createdate=date.format("yyyy-MM-dd hh:mm:ss");</div><div></div><div>date.setMinutes(date.getMinutes()+5);</div><div>var validtime=date.format("yyyy-MM-dd hh:mm:ss");</div><div></div><div></div><div></div><div>db.UserOnlineInfo.update(</div><div>{</div><div>&nbsp; "uid" : "110000350"</div><div>},</div><div>{$set : {</div><div>&nbsp; "uid" : "110000350",&nbsp;</div><div>&nbsp; "createtime" : createdate,</div><div>&nbsp; "validtime" : validtime</div><div>}});</div><div></div><div></div><div></div><div>db.UserOnlineInfo.update(</div><div>{</div><div>&nbsp; "uid" : "110000351"</div><div>},</div><div>{$set : {</div><div>&nbsp; "uid" : "110000351",&nbsp;</div><div>&nbsp; "createtime" : createdate,</div><div>&nbsp; "validtime" : validtime</div><div>}});</div><div><br />2、编写shell脚步：<br />&nbsp;#/bin/bash<div>echo "update&nbsp;mongod begin"</div><div>cd /home/mongodb/mongodb-3.0.2/bin</div><div>./mongo &nbsp;192.168.1.122:27108/YouLiao update.js;</div><div>echo "update mongod success"</div><div><br />3、 执行脚本：</div></div><div>/home/mongodb/mongodb-3.0.2/bin/mongo &nbsp;192.168.1.122:27108/YouLiao /root/www/job/mongo-test/update.js<br /><br />备注：</div><div>mongodb查询、删除类似</div><div></div><br />&nbsp; &nbsp;<img src ="http://www.blogjava.net/17learning/aggbug/427431.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/17learning/" target="_blank">管先飞</a> 2015-09-22 19:25 <a href="http://www.blogjava.net/17learning/archive/2015/09/22/427431.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>