diff --git a/.gitignore b/.gitignore index 98e4d5d..9fbd959 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,20 @@ *.class *.iml +*.swp # Package Files # *.jar *.war *.ear +*.bak +*tree target .idea fileSys bin +node_modules + *.log.* *.log diff --git a/README.md b/README.md index 351d583..2d6718c 100644 --- a/README.md +++ b/README.md @@ -1 +1,39 @@ -# sun \ No newline at end of file +# sun + +# 遇到的一些问题 +1. 中文乱码的问题 + + html乱码可以在html页面设置 + ``` + + + ``` + + 数据响应乱码 + ``` + @RequestMapping(value = "/",produces = "text/html;charset=UTF-8") + ``` + + 请求乱码(这次没遇到,不过记下以后参考) + ``` + @Bean + @Order(Ordered.HIGHEST_PRECEDENCE) + CharacterEncodingFilter characterEncodingFilter() { + CharacterEncodingFilter filter = new CharacterEncodingFilter(); + filter.setEncoding("UTF-8"); + filter.setForceEncoding(true); + return filter; + } + ``` +2. react 获取 form提交数据,用ref属性 比较方便。也可用state对一些关键属性的提交操作 + +3. react + webpack 模块化开发非常爽,做到了组件复用。 + +4. ajax --post-> springboot + + [springboot 配置](http://stackoverflow.com/questions/29313687/trying-to-use-spring-boot-rest-to-read-json-string-from-post) + + 如何 需要send json jquery 要配置"Content-Type": "application/json;charset=UTF-8" + 默认不是这个格式。 + [jquery 设置headers](http://www.cnblogs.com/itjeff/p/6007181.html) +5. SpringBoot下Mysql数据库的中文乱码问题分析 + + http://www.2cto.com/database/201609/543841.html +# 数据库设计 + + + diff --git a/dal/pom.xml b/dal/pom.xml index 7d3c3b7..7cad42a 100644 --- a/dal/pom.xml +++ b/dal/pom.xml @@ -13,5 +13,22 @@ dal - + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 1.1.1 + + + org.apache.commons + commons-dbcp2 + 2.0 + + + mysql + mysql-connector-java + 5.1.27 + + diff --git a/dal/src/main/java/com/helloxyy/sun/config/SunConfig.java b/dal/src/main/java/com/helloxyy/sun/config/SunConfig.java new file mode 100644 index 0000000..9b47307 --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/config/SunConfig.java @@ -0,0 +1,64 @@ +package com.helloxyy.sun.config; + +import org.apache.commons.dbcp2.BasicDataSource; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; + +/** + * Created by xyy on 17-1-1. + */ + +@Configuration +@MapperScan(basePackages = SunConfig.PACKAGE, sqlSessionFactoryRef = "sunSessionFactory") +public class SunConfig { + static final String PACKAGE = "com.helloxyy.sun.mapper"; + + @Value("${db.sun.name}") + private String name; + @Value("${db.sun.password}") + private String password; + @Value("${db.sun.url}") + private String sunUrl; + @Value("${db.jdbc.driver.class}") + private String driverClass; + + + @Bean(name = "sunDataSource") + public DataSource sakilaMasterDataSource() { + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(driverClass); + dataSource.setUrl(sunUrl); + dataSource.setUsername(name); + dataSource.setPassword(password); + + return dataSource; + } + +// @Bean(name = "transactionManager") +// public DataSourceTransactionManager transactionManager(@Qualifier("sunDataSource") DataSource dataSource) throws Exception { +// DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); +// transactionManager.setDataSource(dataSource); +// return transactionManager; +// } + + + @Bean(name = "sunSessionFactory") + public SqlSessionFactory sakilaSqlSessionFactory(@Qualifier("sunDataSource") DataSource dataSource) throws Exception { + final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); + sessionFactory.setDataSource(dataSource); + PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + sessionFactory.setMapperLocations(resolver.getResources("classpath:/mapper/*.xml")); + sessionFactory.setTypeAliasesPackage("com.helloxyy.sun.modle"); + return sessionFactory.getObject(); + } + +} diff --git a/dal/src/main/java/com/helloxyy/sun/controller/BlogController.java b/dal/src/main/java/com/helloxyy/sun/controller/BlogController.java deleted file mode 100644 index 741ade1..0000000 --- a/dal/src/main/java/com/helloxyy/sun/controller/BlogController.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.helloxyy.sun.controller; - -/** - * Created by xyy on 16-12-28. - */ -public class BlogController { -} diff --git a/dal/src/main/java/com/helloxyy/sun/controller/IndexController.java b/dal/src/main/java/com/helloxyy/sun/controller/IndexController.java deleted file mode 100644 index 784f213..0000000 --- a/dal/src/main/java/com/helloxyy/sun/controller/IndexController.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.helloxyy.sun.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -/** - * Created by xyy on 16-12-28. - */ -@Controller -public class IndexController { - @RequestMapping("/") - public String index(ModelMap context){ - - context.put("name","程序员的微生活"); - return "screen/index"; - } - - @RequestMapping("/hello") - @ResponseBody - public String hello(ModelMap context){ - - return "hello"; - } - - -} diff --git a/dal/src/main/java/com/helloxyy/sun/mapper/ArticleMapper.java b/dal/src/main/java/com/helloxyy/sun/mapper/ArticleMapper.java new file mode 100644 index 0000000..27a1e56 --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/mapper/ArticleMapper.java @@ -0,0 +1,20 @@ +package com.helloxyy.sun.mapper; + +import com.helloxyy.sun.modle.ArticleDo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * Created by xyy on 17-1-1. + */ +@Mapper +public interface ArticleMapper { + + List findAll(); + + void insert(ArticleDo article); + List findByTitle(@Param("title") String title); + List findById(@Param("id") int id); +} diff --git a/dal/src/main/java/com/helloxyy/sun/modle/ArticleDo.java b/dal/src/main/java/com/helloxyy/sun/modle/ArticleDo.java new file mode 100644 index 0000000..a79e11a --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/modle/ArticleDo.java @@ -0,0 +1,80 @@ +package com.helloxyy.sun.modle; + +/** + * Created by xyy on 17-1-1. + */ +public class ArticleDo { + + private int id; + private String title; + private String imgSrc; + private String date; + private String digest;// 摘要 + private String link; + private String path; + private int type; + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getDigest() { + return digest; + } + + public void setDigest(String digest) { + this.digest = digest; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getImgSrc() { + return imgSrc; + } + + public void setImgSrc(String imgSrc) { + this.imgSrc = imgSrc; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } +} diff --git a/dal/src/main/java/com/helloxyy/sun/service/ArticleService.java b/dal/src/main/java/com/helloxyy/sun/service/ArticleService.java new file mode 100644 index 0000000..3e28f94 --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/service/ArticleService.java @@ -0,0 +1,57 @@ +package com.helloxyy.sun.service; + +import com.helloxyy.sun.mapper.ArticleMapper; +import com.helloxyy.sun.modle.ArticleDo; +import com.helloxyy.sun.utils.ArticleType; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by xyy on 17-1-2. + */ +@Service +public class ArticleService { + + private static Logger logger = Logger.getLogger(ArticleService.class); + + @Autowired + private ArticleMapper articleMapper; + + public List getArticle(ArticleType type) { + + try { + List list = articleMapper.findAll(); + return list.stream().filter(article -> article.getType() == type.getValue()).collect(Collectors.toList()); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + + return null; + } + + public List findByTitle(String title) { + List list = null; + try { + list = articleMapper.findByTitle(title); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + + return list; + } + + public List findById(int id) { + List list = null; + try { + list = articleMapper.findById(id); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + + return list; + } +} diff --git a/dal/src/main/java/com/helloxyy/sun/utils/ArticleType.java b/dal/src/main/java/com/helloxyy/sun/utils/ArticleType.java new file mode 100644 index 0000000..5ab23b9 --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/utils/ArticleType.java @@ -0,0 +1,18 @@ +package com.helloxyy.sun.utils; + +/** + * Created by xyy on 17-1-2. + */ +public enum ArticleType { + SHARE(0), + ORIGINAL(1); + + private int value; + ArticleType(int i) { + this.value=i; + } + + public int getValue() { + return value; + } +} diff --git a/dal/src/main/java/com/helloxyy/sun/utils/Debug.java b/dal/src/main/java/com/helloxyy/sun/utils/Debug.java new file mode 100644 index 0000000..24ff2d2 --- /dev/null +++ b/dal/src/main/java/com/helloxyy/sun/utils/Debug.java @@ -0,0 +1,15 @@ +package com.helloxyy.sun.utils; + +/** + * Created by xyy on 17-1-4. + */ +public class Debug { + + private static boolean openDebug = true; + + public static void debug(String str) { + if (openDebug == true) { + System.out.println(str); + } + } +} diff --git a/dal/src/main/resources/application.properties b/dal/src/main/resources/application.properties deleted file mode 100755 index 3a67834..0000000 --- a/dal/src/main/resources/application.properties +++ /dev/null @@ -1,4 +0,0 @@ -#App configuration -server.port=7001 -management.port=7002 - diff --git a/dal/src/main/resources/mapper/sun_article.xml b/dal/src/main/resources/mapper/sun_article.xml new file mode 100644 index 0000000..314ec5a --- /dev/null +++ b/dal/src/main/resources/mapper/sun_article.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + id, title ,imgsrc,create_time,digest,link,path,type + + + + title ,imgsrc,create_time,digest,link,path,type + + + + + + + + + + + + + + + INSERT INTO article() + VALUES ( + #{title}, + #{imgSrc}, + #{date}, + #{digest}, + #{link}, + #{path}, + #{type} + ) + + + + + + + + + + + + + diff --git a/dal/src/main/resources/static/index.html b/dal/src/main/resources/static/index.html deleted file mode 100644 index 087bff0..0000000 --- a/dal/src/main/resources/static/index.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - -
- - - -
- -
- -
- -
-
-
-

Sun

-
- - - -
-
-
-

Example

- -
-
-
-
-
-
-                        
-
-                            package l2f.gameserver.model;
-
-                            public abstract class L2Char extends L2Object {
-                              public static final Short ERROR = 0x0001;
-
-                              public void moveTo(int x, int y, int z) {
-                                _ai = null;
-                                log("Should not be called");
-                                if (1 > 5) { // wtf!?
-                                  return;
-                                }
-                              }
-                            }
-                        
-                    
-
-
-
rightxxxxx
-
-
-
-
-
-
- -
-
- - - - - diff --git a/dal/src/main/resources/static/js/markdown.js b/dal/src/main/resources/static/js/markdown.js deleted file mode 100644 index e348b4a..0000000 --- a/dal/src/main/resources/static/js/markdown.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; -const myarea = { - width: 300, - height: 300, -}; -const h3 = {backgroundColor: '#00ff00'} -class MarkdownEditor extends React.Component { - constructor(props) { - super(props); - this.handleChange = this.handleChange.bind(this); - this.state = {value: 'Type some *markdown* here!'}; - } - - handleChange() { - this.setState({value: this.refs.textarea.value}); - } - - getRawMarkup() { - var md = new Remarkable(); - return {__html:md.render(this.state.value)}; - } - - componentDidUpdate( prevProps, prevState){ - hljs.initHighlighting.called = false; - hljs.initHighlighting(); - console.log("componentDidUpdate"); - } - - componentDidMount( prevProps, prevState){ - // hljs.initHighlighting(); - console.log("componentDidMount"); - } - - - render() { - - return ( -
-

Input

- +
+ + + + + ); + } +} + +ReactDOM.render(, document.getElementById("submitArticles")); diff --git a/web/src/main/resources/static/js/admin/writeBlog.js b/web/src/main/resources/static/js/admin/writeBlog.js new file mode 100644 index 0000000..108bf8d --- /dev/null +++ b/web/src/main/resources/static/js/admin/writeBlog.js @@ -0,0 +1,75 @@ +'use strict'; +import MarkdownEditor, {getContent} from "./markdown"; +// import React from 'react'; +// import ReactDOM from 'react-dom'; +class WriteBlog extends React.Component { + + handleSubmit(e) { + e.preventDefault(); + var submitData = { + "title": this.refs.title.value, + "type": this.refs.type.value, + "imgsrc": this.refs.imgsrc.value, + "digest": this.refs.digest.value, + "content": getContent(), + }; + + console.log(submitData); + $.ajax({ + url: "/https/github.com/insert", + type: "POST", + headers: { + // "Accept": "text/plain; charset=utf-8", + "Content-Type": "application/json;charset=UTF-8" + }, + /* + beforeSend: function(jqXHR, settings) { + jqXHR.setRequestHeader('Accept', 'text/plain; charset=utf-8'); + jqXHR.setRequestHeader('Content-Type', 'text/plain; charset=utf-8'); + }, + */ + data: JSON.stringify(submitData), + success: function (data, textStatus, jqXHR) { + alert("数据:" + data + "\n状态:" + textStatus); + console.log("数据:" + data + "\n状态:" + textStatus); + } + }); + } + + render() { + return ( +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+ + + + + + +
+ ); + + } +} + + +ReactDOM.render(, document.getElementById("writeBlog")); diff --git a/web/src/main/resources/static/js/app.js b/web/src/main/resources/static/js/app.js new file mode 100644 index 0000000..668db13 --- /dev/null +++ b/web/src/main/resources/static/js/app.js @@ -0,0 +1,22 @@ +'use strict'; +import ShareBlog from './article'; +import OriginalBlog from './original'; +class SunApp extends React.Component { + + render() { + return ( +
+
+ +
+
+ +
+
+ ); + } + +} + + +ReactDOM.render(, document.getElementById("sunapp")); diff --git a/web/src/main/resources/static/js/article.js b/web/src/main/resources/static/js/article.js new file mode 100644 index 0000000..4a4f1f4 --- /dev/null +++ b/web/src/main/resources/static/js/article.js @@ -0,0 +1,252 @@ +'use strict'; +export function copyarr(arr, start, end) { + var four_article = []; + for (var i = start; i <= end; i++) { + four_article.push(arr[i]); + } + + return four_article; +} +export const hstyle = { + margin: 0, + padding: 0, + border: 0, + fontSize: '100%', + font: 'inherit', + verticalAlign: 'baseline', +} + +const refreshButton = { + position: 'fixed', + width: '7%', + height: '6%', + zIndex: 100, + left: '1%', + mixBlendMode: 'difference', + background: '#606c76', + top: '2%', + cursor: 'pointer', +} +const row_wrap = { + width: '100%', + height: 'auto', +} +const bt_left = { + float: 'left', + // width: '40%', +} + +class Image extends React.Component { + + + render() { + return ( +
+ +
+ ); + } +} + +class Text extends React.Component { + + render() { + var article = this.props.article; + + var link = article.type == '0' ? article.link : "/originalBlog?id=" + article.id; + return ( +
+
{article.date}
+

{article.title}

+ +

{article.digest}

+

MORE

+
+ ); + } +} + + +class LinkArticle extends React.Component { + + render() { + var article = this.props.article; + return ( + article != undefined && article != null && +
+ + +
+
+ + ); + } + + constructor(props) { + super(props); + } +} + + +class BlogGrid extends React.Component { + render() { + return ( +
+ + +
+
+ ); + } +} + +export class Blog extends React.Component { + + + render() { + + var temp = this.props.temp; + return ( + temp.articles != null && +
+ + +
+ + + ); + } +} + +export class TempBlog extends React.Component { + constructor(props) { + super(props); + this.state = { + articles: null, + four_article: [], + next_index: 0, + }; + } + + getArticles() { + $.get(this.props.temp.ajaxurl, function (result) { + var four_article = []; + var next_index = 0; + if (result.length <= 4) { + four_article = result; + next_index = result.length - 1; + } else { + four_article = copyarr(result, 0, 3); + next_index = 3; + } + + this.setState({ + articles: result, + four_article: four_article, + next_index: next_index, + }); + console.log("next_index:" + this.state.next_index); + console.log(result); + + }.bind(this)); + } + + componentWillMount(prevProps, prevState) { + this.getArticles(); + } + + + handleNextClick() { + var next_index = this.state.next_index; + var len = this.state.articles.length; + if (next_index >= len - 1) { + return; + } + var four_article = this.state.four_article; + + if (len - 1 - next_index <= 4) { + four_article = copyarr(this.state.articles, next_index + 1, len - 1); + next_index = len - 1; + } else { + four_article = copyarr(this.state.articles, next_index + 1, next_index + 4); + next_index = next_index + 4; + } + console.log(four_article); + console.log(next_index) + this.setState({ + four_article: four_article, + next_index: next_index, + }); + + } + + handlePreClick() { + var pre_index = this.state.next_index - this.state.four_article.length; + if (pre_index < 0) { + return; + } + var four_article = this.state.four_article; + + if (pre_index - 4 <= 0) { + four_article = copyarr(this.state.articles, 0, pre_index); + } else { + four_article = copyarr(this.state.articles, pre_index - 3, pre_index); + } + console.log(four_article); + console.log("pre_index:" + pre_index); + this.setState({ + four_article: four_article, + next_index: pre_index, + }) + + } + + render() { + return ( +
+
+
+
+ +
+
+ +
+
+
+

{this.props.temp.head}

+

{this.props.temp.info}

+
+
+ +
+ ); + } +} + + +export default class ShareBlog extends React.Component { + + + render() { + + return ( +
+ +
+ ); + } +} + + diff --git a/web/src/main/resources/static/js/head.js b/web/src/main/resources/static/js/head.js new file mode 100644 index 0000000..63e7034 --- /dev/null +++ b/web/src/main/resources/static/js/head.js @@ -0,0 +1,50 @@ +'use strict'; + +class Button extends React.Component { + constructor(props) { + super(props); + this.state = {name: this.props.value}; + } + + + handleClick(arg) { + if(arg=='3'){ + alert("功能暂未对外开放"); + } + } + + + render() { + return ( + + + + ); + } +} + +class Head extends React.Component { + constructor(props) { + super(props); + } + + + render() { + return ( +
+
+
+
+ ); + } +} + + +ReactDOM.render(, document.getElementById("head1")); + + diff --git a/dal/src/main/resources/static/js/lib/browser.min.js b/web/src/main/resources/static/js/lib/browser.min.js similarity index 100% rename from dal/src/main/resources/static/js/lib/browser.min.js rename to web/src/main/resources/static/js/lib/browser.min.js diff --git a/dal/src/main/resources/static/js/lib/bundle.min.js b/web/src/main/resources/static/js/lib/bundle.min.js similarity index 100% rename from dal/src/main/resources/static/js/lib/bundle.min.js rename to web/src/main/resources/static/js/lib/bundle.min.js diff --git a/dal/src/main/resources/static/js/lib/carbon.js b/web/src/main/resources/static/js/lib/carbon.js similarity index 100% rename from dal/src/main/resources/static/js/lib/carbon.js rename to web/src/main/resources/static/js/lib/carbon.js diff --git a/dal/src/main/resources/static/js/lib/highlight.min.js b/web/src/main/resources/static/js/lib/highlight.min.js similarity index 100% rename from dal/src/main/resources/static/js/lib/highlight.min.js rename to web/src/main/resources/static/js/lib/highlight.min.js diff --git a/dal/src/main/resources/static/js/lib/jquery-3.1.1.js b/web/src/main/resources/static/js/lib/jquery-3.1.1.js similarity index 100% rename from dal/src/main/resources/static/js/lib/jquery-3.1.1.js rename to web/src/main/resources/static/js/lib/jquery-3.1.1.js diff --git a/dal/src/main/resources/static/js/lib/prism.js b/web/src/main/resources/static/js/lib/prism.js similarity index 95% rename from dal/src/main/resources/static/js/lib/prism.js rename to web/src/main/resources/static/js/lib/prism.js index 9180534..a0b1642 100644 --- a/dal/src/main/resources/static/js/lib/prism.js +++ b/web/src/main/resources/static/js/lib/prism.js @@ -7,7 +7,7 @@ Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(as|async| Prism.languages.java=Prism.languages.extend("clike",{keyword:/\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/,number:/\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0}}),Prism.languages.insertBefore("java","function",{annotation:{alias:"punctuation",pattern:/(^|[^.])@\w+/,lookbehind:!0}}); !function(){function e(e,t){return Array.prototype.slice.call((t||document).querySelectorAll(e))}function t(e,t){return t=" "+t+" ",(" "+e.className+" ").replace(/[\n\t]/g," ").indexOf(t)>-1}function n(e,n,i){for(var o,a=n.replace(/\s+/g,"").split(","),l=+e.getAttribute("data-line-offset")||0,d=r()?parseInt:parseFloat,c=d(getComputedStyle(e).lineHeight),s=0;o=a[s++];){o=o.split("-");var u=+o[0],m=+o[1]||u,h=document.createElement("div");h.textContent=Array(m-u+2).join(" \n"),h.setAttribute("aria-hidden","true"),h.className=(i||"")+" line-highlight",t(e,"line-numbers")||(h.setAttribute("data-start",u),m>u&&h.setAttribute("data-end",m)),h.style.top=(u-l-1)*c+"px",t(e,"line-numbers")?e.appendChild(h):(e.querySelector("code")||e).appendChild(h)}}function i(){var t=location.hash.slice(1);e(".temporary.line-highlight").forEach(function(e){e.parentNode.removeChild(e)});var i=(t.match(/\.([\d,-]+)$/)||[,""])[1];if(i&&!document.getElementById(t)){var r=t.slice(0,t.lastIndexOf(".")),o=document.getElementById(r);o&&(o.hasAttribute("data-line")||o.setAttribute("data-line",""),n(o,i,"temporary "),document.querySelector(".temporary.line-highlight").scrollIntoView())}}if("undefined"!=typeof self&&self.Prism&&self.document&&document.querySelector){var r=function(){var e;return function(){if("undefined"==typeof e){var t=document.createElement("div");t.style.fontSize="13px",t.style.lineHeight="1.5",t.style.padding=0,t.style.border=0,t.innerHTML=" 
 ",document.body.appendChild(t),e=38===t.offsetHeight,document.body.removeChild(t)}return e}}(),o=0;Prism.hooks.add("complete",function(t){var r=t.element.parentNode,a=r&&r.getAttribute("data-line");r&&a&&/pre/i.test(r.nodeName)&&(clearTimeout(o),e(".line-highlight",r).forEach(function(e){e.parentNode.removeChild(e)}),n(r,a),o=setTimeout(i,1))}),window.addEventListener&&window.addEventListener("hashchange",i)}}(); !function(){"undefined"!=typeof self&&self.Prism&&self.document&&document.querySelector&&(self.Prism.fileHighlight=function(){var e={js:"javascript",py:"python",rb:"ruby",ps1:"powershell",psm1:"powershell",sh:"bash",bat:"batch",h:"c",tex:"latex"};Array.prototype.forEach&&Array.prototype.slice.call(document.querySelectorAll("pre[data-src]")).forEach(function(t){for(var a,s=t.getAttribute("data-src"),n=t,r=/\blang(?:uage)?-(?!\*)(\w+)\b/i;n&&!r.test(n.className);)n=n.parentNode;if(n&&(a=(t.className.match(r)||[,""])[1]),!a){var o=(s.match(/\.(\w+)$/)||[,""])[1];a=e[o]||o}var l=document.createElement("code");l.className="language-"+a,t.textContent="",l.textContent="Loading…",t.appendChild(l);var i=new XMLHttpRequest;i.open("GET",s,!0),i.onreadystatechange=function(){4==i.readyState&&(i.status<400&&i.responseText?(l.textContent=i.responseText,Prism.highlightElement(l)):l.textContent=i.status>=400?"✖ Error "+i.status+" while fetching file: "+i.statusText:"✖ Error: File does not exist or is empty")},i.send(null)})},document.addEventListener("DOMContentLoaded",self.Prism.fileHighlight))}(); -!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var t=[],e={},n=function(){};Prism.plugins.toolbar={};var a=Prism.plugins.toolbar.registerButton=function(n,a){var o;o="function"==typeof a?a:function(t){var e;return"function"==typeof a.onClick?(e=document.createElement("button"),e.type="button",e.addEventListener("click",function(){a.onClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a"),e.href=a.url):e=document.createElement("span"),e.textContent=a.text,e},t.push(e[n]=o)},o=Prism.plugins.toolbar.hook=function(a){var o=a.element.parentNode;if(o&&/pre/i.test(o.nodeName)&&!o.classList.contains("code-toolbar")){o.classList.add("code-toolbar");var r=document.createElement("div");r.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(t=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return e[t]||n})),t.forEach(function(t){var e=t(a);if(e){var n=document.createElement("div");n.classList.add("toolbar-item"),n.appendChild(e),r.appendChild(n)}}),o.appendChild(r)}};a("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var n,a,o=e.getAttribute("data-label");try{a=document.querySelector("template#"+o)}catch(r){}return a?n=a.content:(e.hasAttribute("data-url")?(n=document.createElement("a"),n.href=e.getAttribute("data-url")):n=document.createElement("span"),n.textContent=o),n}}),Prism.hooks.add("complete",o)}}(); +!function(){if("undefined"!=typeof self&&self.Prism&&self.document){var t=[],e={},n=function(){};Prism.plugins.toolbar={};var a=Prism.plugins.toolbar.registerButton=function(n,a){var o;o="function"==typeof a?a:function(t){var e;return"function"==typeof a.handleClick?(e=document.createElement("button"),e.type="button",e.addEventListener("click",function(){a.handleClick.call(this,t)})):"string"==typeof a.url?(e=document.createElement("a"),e.href=a.url):e=document.createElement("span"),e.textContent=a.text,e},t.push(e[n]=o)},o=Prism.plugins.toolbar.hook=function(a){var o=a.element.parentNode;if(o&&/pre/i.test(o.nodeName)&&!o.classList.contains("code-toolbar")){o.classList.add("code-toolbar");var r=document.createElement("div");r.classList.add("toolbar"),document.body.hasAttribute("data-toolbar-order")&&(t=document.body.getAttribute("data-toolbar-order").split(",").map(function(t){return e[t]||n})),t.forEach(function(t){var e=t(a);if(e){var n=document.createElement("div");n.classList.add("toolbar-item"),n.appendChild(e),r.appendChild(n)}}),o.appendChild(r)}};a("label",function(t){var e=t.element.parentNode;if(e&&/pre/i.test(e.nodeName)&&e.hasAttribute("data-label")){var n,a,o=e.getAttribute("data-label");try{a=document.querySelector("template#"+o)}catch(r){}return a?n=a.content:(e.hasAttribute("data-url")?(n=document.createElement("a"),n.href=e.getAttribute("data-url")):n=document.createElement("span"),n.textContent=o),n}}),Prism.hooks.add("complete",o)}}(); !function(){function t(t){"function"!=typeof t||e(t)||r.push(t)}function e(t){return"function"==typeof t?r.filter(function(e){return e.valueOf()===t.valueOf()})[0]:"string"==typeof t&&t.length>0?r.filter(function(e){return e.name===t})[0]:null}function n(t){if("string"==typeof t&&(t=e(t)),"function"==typeof t){var n=r.indexOf(t);n>=0&&r.splice(n,1)}}function a(){Array.prototype.slice.call(document.querySelectorAll("pre[data-jsonp]")).forEach(function(t){t.textContent="";var e=document.createElement("code");e.textContent=i,t.appendChild(e);var n=t.getAttribute("data-adapter"),a=null;if(n){if("function"!=typeof window[n])return e.textContent="JSONP adapter function '"+n+"' doesn't exist",void 0;a=window[n]}var u="prismjsonp"+o++,f=document.createElement("a"),l=f.href=t.getAttribute("data-jsonp");f.href+=(f.search?"&":"?")+(t.getAttribute("data-callback")||"callback")+"="+u;var s=setTimeout(function(){e.textContent===i&&(e.textContent="Timeout loading '"+l+"'")},5e3),d=document.createElement("script");d.src=f.href,window[u]=function(n){document.head.removeChild(d),clearTimeout(s),delete window[u];var o="";if(a)o=a(n,t);else for(var i in r)if(o=r[i](n,t),null!==o)break;null===o?e.textContent="Cannot parse response (perhaps you need an adapter function?)":(e.textContent=o,Prism.highlightElement(e))},document.head.appendChild(d)})}if(self.Prism&&self.document&&document.querySelectorAll&&[].filter){var r=[];Prism.plugins.jsonphighlight={registerAdapter:t,removeAdapter:n,highlight:a},t(function(t){if(t&&t.meta&&t.data){if(t.meta.status&&t.meta.status>=400)return"Error: "+(t.data.message||t.meta.status);if("string"==typeof t.data.content)return"function"==typeof atob?atob(t.data.content.replace(/\s/g,"")):"Your browser cannot decode base64"}return null}),t(function(t,e){if(t&&t.meta&&t.data&&t.data.files){if(t.meta.status&&t.meta.status>=400)return"Error: "+(t.data.message||t.meta.status);var n=e.getAttribute("data-filename");if(null==n)for(var a in t.data.files)if(t.data.files.hasOwnProperty(a)){n=a;break}return void 0!==t.data.files[n]?t.data.files[n].content:"Error: unknown or missing gist file "+n}return null}),t(function(t){return t&&t.node&&"string"==typeof t.data?t.data:null});var o=0,i="Loading…";a()}}(); !function(){"undefined"!=typeof self&&!self.Prism||"undefined"!=typeof global&&!global.Prism||Prism.hooks.add("wrap",function(e){"keyword"===e.type&&e.classes.push("keyword-"+e.content)})}(); !function(){if("undefined"!=typeof self&&self.Prism&&self.document&&Function.prototype.bind){var t=function(t){var e=0,s=0,i=t;if(i.parentNode){do e+=i.offsetLeft,s+=i.offsetTop;while((i=i.offsetParent)&&i.nodeType<9);i=t;do e-=i.scrollLeft,s-=i.scrollTop;while((i=i.parentNode)&&!/body/i.test(i.nodeName))}return{top:s,right:innerWidth-e-t.offsetWidth,bottom:innerHeight-s-t.offsetHeight,left:e}},e=/(?:^|\s)token(?=$|\s)/,s=/(?:^|\s)active(?=$|\s)/g,i=/(?:^|\s)flipped(?=$|\s)/g,o=function(t,e,s,i){this._elt=null,this._type=t,this._clsRegexp=RegExp("(?:^|\\s)"+t+"(?=$|\\s)"),this._token=null,this.updater=e,this._mouseout=this.mouseout.bind(this),this.initializer=i;var n=this;s||(s=["*"]),"Array"!==Prism.util.type(s)&&(s=[s]),s.forEach(function(t){"string"!=typeof t&&(t=t.lang),o.byLanguages[t]||(o.byLanguages[t]=[]),o.byLanguages[t].indexOf(n)<0&&o.byLanguages[t].push(n)}),o.byType[t]=this};o.prototype.init=function(){this._elt||(this._elt=document.createElement("div"),this._elt.className="prism-previewer prism-previewer-"+this._type,document.body.appendChild(this._elt),this.initializer&&this.initializer())},o.prototype.check=function(t){do if(e.test(t.className)&&this._clsRegexp.test(t.className))break;while(t=t.parentNode);t&&t!==this._token&&(this._token=t,this.show())},o.prototype.mouseout=function(){this._token.removeEventListener("mouseout",this._mouseout,!1),this._token=null,this.hide()},o.prototype.show=function(){if(this._elt||this.init(),this._token)if(this.updater.call(this._elt,this._token.textContent)){this._token.addEventListener("mouseout",this._mouseout,!1);var e=t(this._token);this._elt.className+=" active",e.top-this._elt.offsetHeight>0?(this._elt.className=this._elt.className.replace(i,""),this._elt.style.top=e.top+"px",this._elt.style.bottom=""):(this._elt.className+=" flipped",this._elt.style.bottom=e.bottom+"px",this._elt.style.top=""),this._elt.style.left=e.left+Math.min(200,this._token.offsetWidth/2)+"px"}else this.hide()},o.prototype.hide=function(){this._elt.className=this._elt.className.replace(s,"")},o.byLanguages={},o.byType={},o.initEvents=function(t,e){var s=[];o.byLanguages[e]&&(s=s.concat(o.byLanguages[e])),o.byLanguages["*"]&&(s=s.concat(o.byLanguages["*"])),t.addEventListener("mouseover",function(t){var e=t.target;s.forEach(function(t){t.check(e)})},!1)},Prism.plugins.Previewer=o,Prism.hooks.add("after-highlight",function(t){(o.byLanguages["*"]||o.byLanguages[t.language])&&o.initEvents(t.element,t.language)})}}(); diff --git a/dal/src/main/resources/static/js/lib/react-dom.js b/web/src/main/resources/static/js/lib/react-dom.js similarity index 100% rename from dal/src/main/resources/static/js/lib/react-dom.js rename to web/src/main/resources/static/js/lib/react-dom.js diff --git a/dal/src/main/resources/static/js/lib/react.js b/web/src/main/resources/static/js/lib/react.js similarity index 99% rename from dal/src/main/resources/static/js/lib/react.js rename to web/src/main/resources/static/js/lib/react.js index 3b7e463..5922119 100644 --- a/dal/src/main/resources/static/js/lib/react.js +++ b/web/src/main/resources/static/js/lib/react.js @@ -2396,7 +2396,7 @@ var EventPluginHub = { * Stores `listener` at `listenerBank[registrationName][id]`. Is idempotent. * * @param {object} inst The instance, which is the source of events. - * @param {string} registrationName Name of listener (e.g. `onClick`). + * @param {string} registrationName Name of listener (e.g. `handleClick`). * @param {function} listener The callback to store. */ putListener: function (inst, registrationName, listener) { @@ -2413,7 +2413,7 @@ var EventPluginHub = { /** * @param {object} inst The instance, which is the source of events. - * @param {string} registrationName Name of listener (e.g. `onClick`). + * @param {string} registrationName Name of listener (e.g. `handleClick`). * @return {?function} The stored callback. */ getListener: function (inst, registrationName) { @@ -2425,7 +2425,7 @@ var EventPluginHub = { * Deletes a listener from the registration bank. * * @param {object} inst The instance, which is the source of events. - * @param {string} registrationName Name of listener (e.g. `onClick`). + * @param {string} registrationName Name of listener (e.g. `handleClick`). */ deleteListener: function (inst, registrationName) { var PluginModule = EventPluginRegistry.registrationNameModules[registrationName]; @@ -3959,9 +3959,9 @@ function getListeningForDocument(mountAt) { * `ReactBrowserEventEmitter` is used to attach top-level event listeners. For * example: * - * EventPluginHub.putListener('myID', 'onClick', myFunction); + * EventPluginHub.putListener('myID', 'handleClick', myFunction); * - * This would allocate a "registration" of `('onClick', myFunction)` on 'myID'. + * This would allocate a "registration" of `('handleClick', myFunction)` on 'myID'. * * @internal */ @@ -4018,7 +4018,7 @@ var ReactBrowserEventEmitter = _assign({}, ReactEventEmitterMixin, { * Also, `keyup`/`keypress`/`keydown` do not bubble to the window on IE, but * they bubble to document. * - * @param {string} registrationName Name of listener (e.g. `onClick`). + * @param {string} registrationName Name of listener (e.g. `handleClick`). * @param {object} contentDocumentHandle Document which owns the container */ listenTo: function (registrationName, contentDocumentHandle) { @@ -6646,7 +6646,7 @@ var globalIdCounter = 1; * React components. It accepts event listeners and DOM properties that are * valid according to `DOMProperty`. * - * - Event listeners: `onClick`, `onMouseDown`, etc. + * - Event listeners: `handleClick`, `onMouseDown`, etc. * - DOM properties: `className`, `name`, `title`, etc. * * The `style` property functions differently from the DOM API. It accepts an @@ -7064,7 +7064,7 @@ ReactDOMComponent.Mixin = { if (lastProps[propKey]) { // Only call deleteListener if there was a listener previously or // else willDeleteListener gets called when there wasn't actually a - // listener (e.g., onClick={null}) + // listener (e.g., handleClick={null}) deleteListener(this, propKey); } } else if (DOMProperty.properties[propKey] || DOMProperty.isCustomAttribute(propKey)) { @@ -12269,7 +12269,7 @@ var invariant = _dereq_(156); * var MyComponent = React.createClass({ * render: function() { * return ( - *
+ *
* *
* ); @@ -19339,4 +19339,4 @@ module.exports = Object.assign || function (target, source) { }; },{}]},{},[90])(90) -}); \ No newline at end of file +}); diff --git a/dal/src/main/resources/static/js/lib/remarkable.min.js b/web/src/main/resources/static/js/lib/remarkable.min.js similarity index 100% rename from dal/src/main/resources/static/js/lib/remarkable.min.js rename to web/src/main/resources/static/js/lib/remarkable.min.js diff --git a/web/src/main/resources/static/js/lib/temp.js b/web/src/main/resources/static/js/lib/temp.js new file mode 100644 index 0000000..6207c02 --- /dev/null +++ b/web/src/main/resources/static/js/lib/temp.js @@ -0,0 +1,107 @@ + +class ProductCategoryRow extends React.Component { + render() { + return ({this.props.category}); + } +} + +class ProductRow extends React.Component { + render() { + var name = this.props.product.stocked ? + this.props.product.name : + + {this.props.product.name} + ; + return ( + + {name} + {this.props.product.price} + + ); + } +} + +class ProductTable extends React.Component { + render() { + var rows = []; + var lastCategory = null; + this.props.products.forEach((product) => { + if (product.name.indexOf(this.props.filterText) === -1 || (!product.stocked && this.props.inStockOnly)) { + return; + } + if (product.category !== lastCategory) { + rows.push(); + } + rows.push(); + lastCategory = product.category; + }); + return ( + + + + + + + + {rows} +
NamePrice
+ ); + } +} + +class SearchBar extends React.Component { + render() { + return ( +
+ +

+ + {' '} + Only show products in stock +

+
+ ); + } +} + +class FilterableProductTable extends React.Component { + constructor(props) { + super(props); + this.state = { + filterText: '', + inStockOnly: false + }; + } + + render() { + return ( +
+ + +
+ ); + } +} + + +var PRODUCTS = [ + {category: 'Sporting Goods', price: '$49.99', stocked: true, name: 'Football'}, + {category: 'Sporting Goods', price: '$9.99', stocked: true, name: 'Baseball'}, + {category: 'Sporting Goods', price: '$29.99', stocked: false, name: 'Basketball'}, + {category: 'Electronics', price: '$99.99', stocked: true, name: 'iPod Touch'}, + {category: 'Electronics', price: '$399.99', stocked: false, name: 'iPhone 5'}, + {category: 'Electronics', price: '$199.99', stocked: true, name: 'Nexus 7'} +]; + +ReactDOM.render( + , + document.getElementById('container') +); +VIEW COMPILED diff --git a/web/src/main/resources/static/js/original.js b/web/src/main/resources/static/js/original.js new file mode 100644 index 0000000..4467ff5 --- /dev/null +++ b/web/src/main/resources/static/js/original.js @@ -0,0 +1,21 @@ +'use strict'; +import {Blog,copyarr,TempBlog} from './article'; + + +export default class OriginalBlog extends React.Component { + + render() { + + return ( +
+ +
+ ); + } +} + + diff --git a/web/src/main/resources/static/js/originalDetail.js b/web/src/main/resources/static/js/originalDetail.js new file mode 100644 index 0000000..81812eb --- /dev/null +++ b/web/src/main/resources/static/js/originalDetail.js @@ -0,0 +1,51 @@ +'use strict'; +class OriginalDetail extends React.Component { + constructor(props) { + super(props); + this.handleChange = this.handleChange.bind(this); + this.state = {value: null}; + } + + getBlog() { + $.get("/detail?id="+window.blogid, function (result) { + console.log(result); + this.setState({value: result}); + }.bind(this)); + } + + highLight() { + hljs.initHighlighting.called = false; + hljs.initHighlighting(); + } + + handleChange() { + this.getBlog(); + } + + getRawMarkup() { + var md = new Remarkable(); + return {__html: md.render(this.state.value)}; + } + + // 先插入dom + componentDidMount(prevProps, prevState) { + console.log("didmount"); + this.getBlog(); + } + + // 再高亮 + componentDidUpdate(prevProps, prevState) { + console.log("update"); + this.highLight(); + } + + render() { + + return ( +
+ ); + } +} + +ReactDOM.render(, document.getElementById('originalBlog')); + diff --git a/web/src/main/resources/static/package.json b/web/src/main/resources/static/package.json new file mode 100644 index 0000000..2a0f7c5 --- /dev/null +++ b/web/src/main/resources/static/package.json @@ -0,0 +1,39 @@ +{ + "name": "react-webpack", + "version": "1.0.0", + "description": "webpack demo", + "main": "index.js", + "scripts": { + "start": "webpack-dev-server --hot --progress --colors", + "build": "webpack --progress --colors" + }, + "keywords": [ + "react", + "webpack" + ], + "author": "xyy", + "devDependencies": { + "babel-core": "^6.5.2", + "babel-loader": "^6.2.2", + "babel-plugin-react-transform": "^2.0.0", + "css-loader": "^0.23.1", + "less": "^2.6.0", + "less-loader": "^2.2.2", + "react-hot-loader": "^1.3.0", + "react-transform-hmr": "^1.0.2", + "webpack": "^1.12.11", + "webpack-dev-server": "^1.14.1" + }, + "dependencies": { + "babel-preset-es2015": "^6.5.0", + "babel-preset-react": "^6.5.0", + "graceful": "~1.0.0", + "html-webpack-plugin": "^2.8.2", + "lodash": "~3.10.1", + "react": "^0.14.7", + "react-dom": "^0.14.7", + "react-kendo": "~0.13.11", + "react-router": "^2.0.0", + "recluster": "~0.3.7" + } +} diff --git a/web/src/main/resources/static/webpack.config.js b/web/src/main/resources/static/webpack.config.js new file mode 100644 index 0000000..313197b --- /dev/null +++ b/web/src/main/resources/static/webpack.config.js @@ -0,0 +1,23 @@ +var webpack = require('webpack'); +var path = require('path'); + +module.exports = { + entry: { + // 'webpack/hot/dev-server', + // 'webpack-dev-server/client?http://localhost:8080', + 'app': './js/app.js', + 'writeBlog': './js/admin/writeBlog.js', + }, + output: { + path: path.resolve("./build"), + filename: '[name].bundle.js', + // publicPath: '/static' + }, + module: { + loaders: [{ + test: /\.jsx?$/, + loaders: ['babel-loader?presets[]=es2015&presets[]=react'], + include: path.join(__dirname, '.') + }] + }, +}; diff --git a/dal/src/main/resources/templates/layout/default.vm b/web/src/main/resources/templates/layout/default.vm similarity index 58% rename from dal/src/main/resources/templates/layout/default.vm rename to web/src/main/resources/templates/layout/default.vm index 5f7ccca..e0bfaff 100755 --- a/dal/src/main/resources/templates/layout/default.vm +++ b/web/src/main/resources/templates/layout/default.vm @@ -1,7 +1,9 @@ - + + + sun @@ -17,17 +19,28 @@ +## + + +##
+##

Unicorns

+##

All the things

+##
-
+ ## #parse('layout/sidebar.vm') -
-
- $screen_content -
-
-
+ $screen_content + diff --git a/dal/src/main/resources/templates/layout/sidebar.vm b/web/src/main/resources/templates/layout/sidebar.vm similarity index 100% rename from dal/src/main/resources/templates/layout/sidebar.vm rename to web/src/main/resources/templates/layout/sidebar.vm diff --git a/web/src/main/resources/templates/screen/admin/submitArticles.vm b/web/src/main/resources/templates/screen/admin/submitArticles.vm new file mode 100644 index 0000000..59b9f64 --- /dev/null +++ b/web/src/main/resources/templates/screen/admin/submitArticles.vm @@ -0,0 +1,2 @@ +
+ diff --git a/web/src/main/resources/templates/screen/admin/writeBlog.vm b/web/src/main/resources/templates/screen/admin/writeBlog.vm new file mode 100644 index 0000000..454c32c --- /dev/null +++ b/web/src/main/resources/templates/screen/admin/writeBlog.vm @@ -0,0 +1,2 @@ +
+ diff --git a/web/src/main/resources/templates/screen/index.vm b/web/src/main/resources/templates/screen/index.vm new file mode 100755 index 0000000..9ae3bca --- /dev/null +++ b/web/src/main/resources/templates/screen/index.vm @@ -0,0 +1,38 @@ +
+ + + +
+ +
+ +
+ +
+
+
+

Sun

+
+ + + +
+
+
+

Good Blogs For Everyone

+ + +
+ + +
+ + diff --git a/web/src/main/resources/templates/screen/originalBlog.vm b/web/src/main/resources/templates/screen/originalBlog.vm new file mode 100644 index 0000000..af58cac --- /dev/null +++ b/web/src/main/resources/templates/screen/originalBlog.vm @@ -0,0 +1,5 @@ +
+ + diff --git a/dal/src/main/resources/templates/screen/index.vm b/web/src/main/resources/templates/screen/temp.vm old mode 100755 new mode 100644 similarity index 65% rename from dal/src/main/resources/templates/screen/index.vm rename to web/src/main/resources/templates/screen/temp.vm index 392695b..90e6d5d --- a/dal/src/main/resources/templates/screen/index.vm +++ b/web/src/main/resources/templates/screen/temp.vm @@ -1,40 +1,3 @@ -
- - - -
- -
- -
- -
-
-
-

Sun

-
- - - -
-
-
-

Example

- -
-
-

${name}

-

介绍

-
-
@@ -71,3 +34,66 @@
+ +
+
+
+ +
+
+
March 29, 2014
+

A NEW INVENTION FOR LOVERS WHO LOVE

+ +

Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum ....

+

MORE

+
+
+
+
+
+ +
+
+
March 29, 2014
+

A NEW INVENTION FOR LOVERS WHO LOVE

+ +

Lorem Ipsum is simply dummy text of the printing and typesetting industry Lorem Ipsum ....

+

MORE

+
+
+
+
+
+ + + +
+ + + +
+ +
+ +
+ +
+
+
+

Sun

+
+ + + +
+
+
+

${name}

diff --git a/web/src/test/java/com/helloxyy/sun/test/DailyTest.java b/web/src/test/java/com/helloxyy/sun/test/DailyTest.java new file mode 100644 index 0000000..721ee7d --- /dev/null +++ b/web/src/test/java/com/helloxyy/sun/test/DailyTest.java @@ -0,0 +1,23 @@ +package com.helloxyy.sun.test; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * Created by xyy on 17-1-6. + */ +public class DailyTest { + + public static void main(String[] args) throws ParseException { + + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + Date date=df.parse("2017-01-04 21:38:20"); + + System.out.println(date); + + + } +} diff --git a/web/src/test/java/com/helloxyy/sun/test/ResourceTest.java b/web/src/test/java/com/helloxyy/sun/test/ResourceTest.java new file mode 100644 index 0000000..c3b3979 --- /dev/null +++ b/web/src/test/java/com/helloxyy/sun/test/ResourceTest.java @@ -0,0 +1,70 @@ +package com.helloxyy.sun.test; + +import com.helloxyy.sun.BootStrap; +import com.helloxyy.sun.utils.FileUtil; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Date; + +/** + * Created by xyy on 17-1-1. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = BootStrap.class) +@WebAppConfiguration +public class ResourceTest { + + @Test + public void test1() throws IOException { + Resource resource = new ClassPathResource("/blog/test.md"); + String fileName = resource.getFilename(); + System.out.println(fileName); + System.out.println(resource.getURL()); + System.out.println(resource.getURI()); + // if (resource.isReadable()) { + // //每次都会打开一个新的流 + // InputStream is = resource.getInputStream(); + // this.printContent(is); + // } + + String content = FileUtil.read(resource.getFile()); + System.out.println(content); + } + + @Test + public void test2() throws Exception{ + System.out.println(FileUtil.readRelativeFile("/blog/test.md")); + } + + + @Test + public void testDate(){ + Date date=new Date("2017-01-04 21:38:20"); + System.out.println(date); + } + + private void printContent(InputStream is) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + String line; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + if (is != null) { + is.close(); + } + if (br != null) { + br.close(); + } + } + +}