暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

【大数据开发】Elasticsearch推荐系统(七)

数据信息化 2020-07-25
306



Elasticsearch

之小说详情页功能开发-小说内容(七)

Novel detail page function development - Novel content

简介

本文将介绍如何开发小说章节跳转页以及小说内容页

页面展示:

01

详情页目录开发

    需要启动Hbase服务,小说内容的链接地址是存在Hbase中的。


(1)Controller代码:

    /** 
* @Description: 文章页面
* @Param: [attr]
* @return: java.lang.String
* @Author: zhangjingyu
* @Date: 2020/07/22
*/
@RequestMapping(value="content")
public String content(String nid,String name,String chapter,String author,Map<String,Object> map)
throws IOException {
//按照小说name和chapter查找该小说
ChapterDetail chapterDetail = chapterServiceImpl.getChapterDetail(name, chapter,nid,author);
map.put("content",chapterDetail);
return "content";
}


(2)Service代码:

@Override
public ChapterDetail getChapterDetail(String name, String chapter,String nid,String author)
throws IOException {
ChapterDetail chapterDetail = new ChapterDetail();
String rowKey = JavaUtils.md5(name+chapter);
chapterDetail.setChapterName(chapter);
chapterDetail.setNovelName(name);
chapterDetail.setNovelId(nid);
chapterDetail.setAuthorName(author);
Connection connection = HbaseUtils.client();
Table table = connection.getTable(TableName.valueOf(CommonUtil.hbase_novel_detail));
Get get = new Get(rowKey.getBytes());
Result result = table.get(get);
for (KeyValue keyValue:result.raw()) {
String key = new String(keyValue.getQualifier());
if("chapterUrl".equals(key)){
chapterDetail.setChapterUrl(new String(keyValue.getValue()));
}
}
return chapterDetail;
}


(3)HBase配置代码:

public class HbaseUtils {


private static Connection conn = null;


public static Connection client() throws IOException {
if(conn != null){
return conn;
}




Configuration configuration = HBaseConfiguration.create();
configuration.set("hbase.zookeeper.property.clientPort", "2181");
configuration.set("hbase.zookeeper.quorum", CommonUtil.HBASE_SERVER);
//集群配置↓
//configuration.set("hbase.zookeeper.quorum", "101.236.39.141,101.236.46.114,101.236.46.113");
// configuration.set("hbase.master", "192.168.148.200:60000");
Connection connection = ConnectionFactory.createConnection(configuration);


return connection;
}
}


(4)常用属性项:

public class CommonUtil {
public final static String index_search = "novel" ;
public final static String index_novel_category_count = "novel_category_count" ;
public final static String index_detail_search = "novel_detail" ;
public final static String HBASE_SERVER = "bigdata-pro-m01.kfk.com" ;
public final static String hbase_novel_detail = "novel_detail" ;
public final static String index_novel_countsort = "novel_author_countsort";
}

02

启动相关服务

(1)启动hadoop服务:

[user@bigdata-pro-m01 hadoop-2.7.0]$ sbin/hadoop-daemon.sh start namenode
[user@bigdata-pro-m01 hadoop-2.7.0]$ sbin/hadoop-daemon.sh start datanode

(2)启动zookeeper服务:

[user@bigdata-pro-m01 zookeeper-3.4.5-cdh5.5.0]$ bin/zkServer.sh start

(3)启动hbase服务:

[user@bigdata-pro-m01 hbase-1.3.3]$ bin/start-hbase.sh
[user@bigdata-pro-m01 hbase-1.3.3]$ bin/hbase shell

扫描二维码 关注我们

微信号 : BIGDT_IN


文章转载自数据信息化,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论