2018/8/24 18:42分
blog系统基本上是从0开始开发代码,包括vue,java,数据库设计。大概从2018/1/12开始
blog博客地址:http://yhmpianzi.imwork.net:9902
solo博客地址:http://yhmpianzi.imwork.net:8888/solo
两个博客地址都部署在thinkCenter上。通过花生壳做的域名:yhmpianzi.imwork.net。在电信猫上做的端口映射。以至于在外网能访问
以下是两个博客系统同步文章关键代码,比较low
blog同步关键代码:
//文章推送mysolo博客系统
JSONObject jsonObject= new JSONObject();
JSONObject jsonObject2= new JSONObject();
jsonObject.put(<span class="hljs-string">"userEmail"</span>, blogArticleWithBLOBs.getArticleAuthorEmail());
jsonObject2.put(<span class="hljs-string">"articleCommentable"</span>, <span class="hljs-keyword">true</span>);
jsonObject2.put(<span class="hljs-string">"articleContent"</span>, blogArticleWithBLOBs.getArticleContent());
jsonObject2.put(<span class="hljs-string">"articleIsPublished"</span>, <span class="hljs-keyword">true</span>);
jsonObject2.put(<span class="hljs-string">"articleSignId"</span>, <span class="hljs-string">"1"</span>);
jsonObject2.put(<span class="hljs-string">"articleTags"</span>, blogArticleWithBLOBs.getArticleTags());
jsonObject2.put(<span class="hljs-string">"articleTitle"</span>, blogArticleWithBLOBs.getArticleTitle());
jsonObject2.put(<span class="hljs-string">"articleViewPwd"</span>, <span class="hljs-string">""</span>);<span class="hljs-comment">//文章查看密码默认为空</span>
jsonObject2.put(<span class="hljs-string">"postToCommunity"</span>, <span class="hljs-keyword">true</span>);
String abstractStr = blogArticleWithBLOBs.getArticleContent().length() >= <span class="hljs-number">30</span> ? blogArticleWithBLOBs.getArticleContent().substring(<span class="hljs-number">0</span>, <span class="hljs-number">29</span>) : blogArticleWithBLOBs.getArticleContent();
jsonObject2.put(<span class="hljs-string">"articleAbstract"</span>, abstractStr);
jsonObject.put(<span class="hljs-string">"article"</span>, jsonObject2);
logger.info(<span class="hljs-string">"文章开始同步mysolo博客系统入参:"</span> + jsonObject.toString());
// String resultStr = HttpUtils.post(CommonConst.mysoloSaveArticleUrl, jsonObject.toString());
// boolean resultStr = HttpClientUtils.post(CommonConst.mysoloSaveArticleUrl, jsonObject.toString(), 100000);
String resultStr = MyHttpUtils.post(CommonConst.mysoloSaveArticleUrl, jsonObject.toString(), 100000);
logger.info(<span class="hljs-string">"文章同步mysolo博客系统结果:"</span> + resultStr);</code></pre><p>solo文章同步保存接口定义:</p><pre style="max-width:100%;overflow-x:auto;"><code class="java hljs" codemark="1"> <span class="hljs-meta">@RequestProcessing</span>(value = <span class="hljs-string">"/console/saveArticleForBlog/"</span>, method = HTTPRequestMethod.POST)
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">saveArticleForBlog</span><span class="hljs-params">(<span class="hljs-keyword">final</span> HttpServletRequest request, <span class="hljs-keyword">final</span> HttpServletResponse response, <span class="hljs-keyword">final</span> HTTPRequestContext context,
<span class="hljs-keyword">final</span> JSONObject requestJSONObject)</span> <span class="hljs-keyword">throws</span> Exception </span>{
LOGGER.info(<span class="hljs-string">"创建文章:"</span> + requestJSONObject.toString());
<span class="hljs-keyword">final</span> JSONRenderer renderer = <span class="hljs-keyword">new</span> JSONRenderer();
context.setRenderer(renderer);
<span class="hljs-keyword">final</span> JSONObject ret = <span class="hljs-keyword">new</span> JSONObject();
<span class="hljs-keyword">try</span> {
String email = requestJSONObject.getString(User.USER_EMAIL) != <span class="hljs-keyword">null</span> ?
requestJSONObject.getString(User.USER_EMAIL) : <span class="hljs-string">""</span>;
JSONObject jsonObject = userRepository.getByEmail(email);
LOGGER.info(<span class="hljs-string">"通过email得到的用户信息:"</span> + jsonObject.toString());
requestJSONObject.getJSONObject(Article.ARTICLE).put(Article.ARTICLE_AUTHOR_EMAIL, jsonObject.getString(User.USER_EMAIL));
<span class="hljs-comment">//保存文章</span>
<span class="hljs-keyword">final</span> String articleId = articleMgmtService.addArticle(requestJSONObject);
ret.put(Keys.OBJECT_ID, articleId);
ret.put(Keys.MSG, langPropsService.get(<span class="hljs-string">"addSuccLabel"</span>));
ret.put(Keys.STATUS_CODE, <span class="hljs-keyword">true</span>);
renderer.setJSONObject(ret);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">final</span> ServiceException e) {
LOGGER.log(Level.ERROR, e.getMessage());
<span class="hljs-keyword">final</span> JSONObject jsonObject = QueryResults.defaultResult();
jsonObject.put(Keys.MSG, e.getMessage());
renderer.setJSONObject(jsonObject);
}
}</code></pre><p><br></p><p>第一篇同步文章:</p><p>图1</p><p><img src="http://p57h8rh2b.bkt.clouddn.com/file/1535100584161.png" alt=""><br></p><p>图2</p><p><img src="http://p57h8rh2b.bkt.clouddn.com/file/1535100614913.png" alt=""><br></p><p><br></p>
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于