A.mysql5.6 java
mysql設置編碼:
node
0.如果您肯定你的mysql是UTF-8編碼的,能夠直接進入底4步驗證。
mysql
1.下載https://github.com/pgq10240817/PlayNews/blob/master/conf/db/my.ini git
2.把1下載的文件放到您安裝目錄下面,能夠直接命爲my.ini(默認是沒有改文件的,默認是有my-default.ini).
github
3. 而後重啓mysq打開cmd,輸入services.msc 進入服務管理,定位到MySql,右鍵從新啓動。
sql
4.打開cmd,進入到%MYSQL%/bin(若是設置了mysql環境變量,能夠略過),輸入mysql,
數據庫
再次輸入 json
show variables like 'char%';
mysql> show variables like 'char%'; +--------------------------+------------- -+ | Variable_name | Value | +--------------------------+------------- -+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8
打開windows環境變量設置,添加系統變量:
windows
PLAY_OPTS:-Dfile.encoding=GBK
樓主嘗試過改成UTF八、UTF-8,然而仍是亂碼。。。。。
app
C.建立數據庫:
運行:https://github.com/pgq10240817/PlayNews/blob/master/conf/db/database.sql
建立數據庫,主要是作了下默認編碼。
D.play配置:
1.數據庫配置:
參考https://github.com/pgq10240817/PlayNews/blob/master/client/myNews/conf/db.conf
# Database configuration # db.default.url="jdbc:mysql://127.0.0.1:3306/dbnews1?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull" db.default.driver=com.mysql.jdbc.Driver db.default.url="jdbc:mysql://127.0.0.1/dbnews1" db.default.user=root db.default.pass="123456" # Ebean configuration #ebean.default="com.yhpl.model.*" #evolutionplugin=disabled ebean.default="models.*"
以上代碼能夠下載play project/conf/application.conf下面,也能夠新建一個db.conf,而後application.conf加入
include "db.conf"就能夠了。
2.常量配置:
參考:https://github.com/pgq10240817/PlayNews/blob/master/client/myNews/conf/http.conf
配置了網易音樂的一些經常使用連接,而後https://github.com/pgq10240817/PlayNews/blob/master/client/myNews/app/com/yhpl/utils/NewsUrlUtil.java
NewsUtil提供了對該類的寫訪問。
3.play路由配置:
https://github.com/pgq10240817/PlayNews/blob/master/client/myNews/conf/routes
暫時只是配置了以下:
GET /initChannels controllers.CaptureController.initChannels() GET /initNews controllers.CaptureController.initNews()
其中initChannels表明初始化頻道,initNews表明讀取頻道的value去初始化新聞。
本次數據來源是採用網易新聞的來源。總共會採集2個分類,1:新聞頻道,2:頻道下的新聞。
經過fiddler抓包,發現網易新聞的數據包格式以下:
1:頻道
https://github.com/pgq10240817/PlayNews/blob/master/conf/data/fiddler/channels.txt
2:新聞
https://github.com/pgq10240817/PlayNews/blob/master/conf/data/fiddler/news.txt
其中2中的抓包須要用到1的頻道ID
經過分析數據格式發現,獲取頻道的內容的URL是固定的,獲取新聞須要用到3個參數,頻道ID,page,pageCount。
Bean類位於:
https://github.com/pgq10240817/PlayNews/tree/master/client/myNews/app/models
下Channels.java,News.java。
1.頻道採集:
public static Result initChannels() { NewChannalsVo chanals = (NewChannalsVo) JsonFileUtil.getGetUrlContentAsObject(NewsUrlUtil.getChannelUrl(), NewChannalsVo.class); if (chanals != null) { NewChannalVo[] channelArray = chanals.gettList(); List<Channels> beans = new ArrayList<Channels>(); for (int i = 0; i < channelArray.length; i++) { NewChannalVo jsonObj = channelArray[i]; Channels bean = new Channels(); bean.cname = jsonObj.getTname(); bean.cid = jsonObj.getTid(); bean.subnum = jsonObj.getSubnum(); beans.add(bean); } Ebean.beginTransaction(); for (int i = 0; i < channelArray.length; i++) { Channels bean = beans.get(i); Channels target = Channels.getChannelWithCname(bean.cname); if (target == null) { Ebean.save(bean); } else { System.out.println("exist -- " + target.cname); } } Ebean.commitTransaction(); } return ok("init Channels success"); }
public static Result initNews() { Page<Channels> pageChannel = Channels.page(1, 20, "id", "asc"); if (pageChannel.getTotalRowCount() > 0) { List<Channels> channelBeans = pageChannel.getList(); if (!CollectionUtil.isEmpty(channelBeans)) { for (int i = 0; i < channelBeans.size(); i++) { // A.解析數據 Channels channelBean = channelBeans.get(i); String url = NewsUrlUtil.getChannelNewsUrlWithCidPageCount(channelBean.cid); JsonNode node = JsonFileUtil.getGetUrlContentAsJsonNode(url); ArrayNode arrayNodes = (ArrayNode) node.get(channelBean.cid); Iterator<JsonNode> iter = arrayNodes.iterator(); List<News> mNews = new ArrayList<News>(); while (iter.hasNext()) { JsonNode childNode = iter.next(); NewsVo childNews = Json.fromJson(childNode, NewsVo.class); News news = new News(); news.cid = channelBean.cid; news.cp = childNews.getSource(); news.icon = childNews.getImgsrc(); news.url = childNews.getUrl(); news.title = childNews.getTitle(); news.snapDetail = childNews.getDigest(); news.time = DateUtil.getDateFromString(childNews.getPtime()); mNews.add(news); System.out.println("child:" + childNews); } // B.過濾數據庫 CollectionUtil.trimListWithFilter(mNews, new TrimFilter<News>() { @Override public boolean isFilter(News t) { return t != null && News.getNewsWithTitle(t.title) != null; } }); // C.POJO -> DB if (!CollectionUtil.isEmpty(mNews)) { System.out.println("save --- > :" + channelBean.cid); Ebean.save(mNews); } } } } return ok("init News success"); }
3.運行play以後,第一次初始化會要求add scripts,點擊add便可。
昨天在wooyun提交的漏洞又是審覈不經過,理由是:
沒法聯繫到廠商而且問題影響不大。。。
那個道友助我一臂啊。。。
下次估計會在國慶節後更,內容主要是,編寫接口共客戶端調用,會有2個接口,獲取頻道,獲取頻道下的新聞。