实现:
使用java程序读取mysql数据库中的商品信息,然后创建solr文档对象,把商品信息写入索引库。
Dao
多表查询,要创建相应的POJO和Mapper。
POJO:1
2
3
4
5
6
7
8
9public class Item {
private String id;
private String title;
private String sell_point;
private long price;
private String image;
private String category_name;
private String item_des;
}
Mapper:1
2
3public interface ItemMapper {
List<Item> getItemList();
}
- xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.izheyi.search.mapper.ItemMapper" >
<select id="getItemList" resultType="com.izheyi.search.pojo.Item">
SELECT
a.id,
a.title,
a.sell_point,
a.price,
a.image,
b. NAME category_name
FROM
tb_item a
LEFT JOIN tb_item_cat b ON a.cid = b.id
</select>
</mapper>
Service
1 | @Service |
需要配置applicationContext-solr.xml。
Controller
1 | @Controller |