在其它的地方调用setSpecMap(自己写的get和set方法)方法。说是找不到,报错信息:没有为类型 TbItem 定义方法 setSpecMap(Map);在其它的地方调用setspecmap方法.说是找不到;我调用其他的get和set方法又是可以的(如:getld和setld) .
文件一(中的代码):
package com.pinyougou.pojo;
public class TbItem implements Serializable{
@Field
private Long id;
@Field("item_title")
private String title;
private String sellPoint;
@Field("item_price")
private BigDecimal price;
private Integer stockCount;
private Integer num;
private String barcode;
@Field("item_image")
private String image;
@Field("item_goodsid")
private Long goodsId;
private String sellerId;
private String cartThumbnail;
@Field("item_category")
private String category;
@Field("item_brand")
private String brand;
private String spec;
@Field("item_seller")
private String seller;
@Dynamic
@Field("item_spec_*")
private Map<String,String> specMap;
public Map<String, String> getSpecMap() {
return specMap;
}
public void setSpecMap(Map<String, String> specMap) {
this.specMap = specMap;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title == null ? null : title.trim();
}
.............
}
文件二(中的代码,也是出错的地方):
package com.pinyougou.solrutil;
import java.util.List;
import java.util.Map;
@Component
public class SolrUtil {
@Autowired
private TbItemMapper itemMapper;
@Autowired
private SolrTemplate solrTemplate;
/**
* 导入商品数据
*/
public void importItemData(){
TbItemExample example=new TbItemExample();
Criteria criteria = example.createCriteria();
criteria.andStatusEqualTo("1");//已审核
List<TbItem> itemList = itemMapper.selectByExample(example);
System.out.println("=====商品列表=====");
for(TbItem item:itemList){
System.out.println(item.getId()+" "+ item.getTitle()+ " "+item.getPrice());
Map specMap = JSON.parseObject(item.getSpec(), Map.class);//从数据库中提取规格json字符串转换为map
item.setSpecMap(specMap);
}
solrTemplate.saveBeans(itemList);
solrTemplate.commit();
System.out.println("=======结束=======");
}
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("classpath*:spring/applicationContext*.xml");
SolrUtil solrUtil= (SolrUtil) context.getBean("solrUtil");
solrUtil.importItemData();
}
}