import java.io.Serializable;
public class TbItemResult implements Serializable {
private long id;
private long tbTtemCid;
private String tbItemCname;
private String tbItemTitle;
private String tbItemSellPoint;
private String tbItemDesc;
public long getId(){
return id;
}
public void setId(long id){
this.id=id;
}
public long getTbTtemCid(){
return tbTtemCid;
}
public void setTbTtemCid(long tbTtemCid){
this.tbTtemCid=tbTtemCid;
}
public String getTbItemCname(){
return tbItemCname;
}
public void setTbItemCname(String tbItemCname){
this.tbItemCname=tbItemCname;
}
public String getTbItemTitle(){
return tbItemTitle;
}
public void setTbItemTitle(String tbItemTitle){
this.tbItemTitle=tbItemTitle;
}
public String getTbItemSellPoint(){
return tbItemSellPoint;
}
public void setTbItemSellPoint(String tbItemSellPoint){
this.tbItemSellPoint=tbItemSellPoint;
}
public String getTbItemDesc(){
return tbItemDesc;
}
public void setTbItemDesc(String tbItemDesc){
this.tbItemDesc=tbItemDesc;
}
}
创建搜索服务提供者
- 创建myshop-service-search-provider服务提供者项目
- MyShopServiceSearchProviderApplication
@EnableHystrix
@EnableHystrixDashboard
@SpringBootApplication(scanBasePackages="com.oxfrod.myshop")
@MapperScan(basePackages="com.oxford.myshop.service.search.provider.mapper")
public class MyShopServiceSearchProviderApplication {
public static void main(String[] args) {
SpringApplication.run(MyShopServiceSearchProviderApplication.class,args);
Main.main(args);
}
}
- 在项目中创建TbItemResultMapper接口用于查询MySQL中的数据,用于插入到Solr数据库中
@Respository
public interface TbItemResultMapper {
List<TbItemResult> selectAll();
}
Spring的四大注解:
1. @Controller
2. @Service
3. @Component
4. @Repository
- 在resource中创建mapper包用于创建TbContentCategoryMapper.xml
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.oxford.myshop.service.search.provider.mapper.TbItemResultMapper">
<resultMap id="BaseResultMap" type="com.oxford.myshop.service.search.domainTbItemResult">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="tb_item_cid" jdbcType="BIGINT" property="tbItemCid" />
<result column="tb_item_cname" jdbcType="VARCHAR" property="tbItemCname" />
<result column="tb_item_title" jdbcType="VARCHAR" property="tbItemTitle" />
<result column="tb_item_sell_point" jdbcType="VARCHAR" property="tbItemSellPoint" />
<result column="tb_item_desc" jdbcType="VARCHAR" property="tbItemDesc" />
</reslutMap>
<select id="selectAll" resultMap="BaseResultMap">
select
a.id,
a.title as tb_item_title,
a.sell_point as tb_item_sell_point,
a.cid as tb_item_cid,
b.name as tb_item_cname,
c.item_desc as tb_item_desc
from
tb_item as a
left join tb_item_cat as b
on a.cid=b.id
left join tb_item_desc as c
on a.id=c.item_id
</select>
</mapper>
初始化Solr:
public void initSolr() {
List<TbItemResult> tbItemResult=tbItemResultMapper.selectAll();
try{
SolrInputDocument document=null;
for(TbItemResult tbItemResult:tbItemResults){
document=new SolrInputDocument();
document.addFiled("id",tbItemResult.getId());
document.addFiled("tb_item_cid",tbItemResult.getTbItemCid());
document.addFiled("tb_item_cname",tbItemResult.getTbItemCname());
document.addFiled("tb_item_title",tbItemResult.getTbItemTitle());
document.addFiled("tb_item_sell_point",tbItemResult.getTbItemSellPoint());
document.addFiled("tb_item_desc",tbItemResult.getTbItemDesc());
solrClient.add(document);
solrClient.commit();
}
}catch(SolrServerException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
推荐阅读
- 理解HTTPS及配置Django+HTTPS开发环境
- 自制蜜桔干,如何自制桂花茶
- 软件测试开发实战|接口自动化测试框架开发
- 浅谈在Linux中如何将脚本做成系统服务开机自启动
- 我们将如何在火星上生活 火星在地球
- 如何在主流浏览器上正常使用只兼容IE的“上古网站”?
- 八种实用的免费游戏开发软件工具
- 如何用谷歌关键词规划师挖掘有效关键词?
- 云呼叫中心的核心功能有哪些?企业如何应用?
- 如何快速去水印批量搬运短视频,教你玩转自媒体短视频