单删
@RequestMapping("/del")
@ResponseBody
public boolean del(String id,HttpServletRequest request) throws SolrServerException, IOException {
//mysql删除
cs.del(id);
//solr删除
sc.deleteById(id);
sc.commit();
//静态页面删除
String path = request.getSession().getServletContext().getRealPath("/");
File file = new File(path+"/page/"+id+".html");
file.delete();
return true;
}
修改
@RequestMapping("/upd")
@ResponseBody
public boolean upd(Contract contract) throws IOException, SolrServerException {
//mysql修改
cs.upd(contract);
//solr修改
Contract contract2 = cs.getContract(contract.getId());
contract.setTname(contract2.getTname());
sc.addBean(contract);
sc.commit();
return true;
}
添加
@RequestMapping("/add")
@ResponseBody
public boolean add(Contract contract) throws IOException, SolrServerException {
//mysql新增
cs.add(contract);
//solr新增
Contract contract2 = cs.getContract(contract.getId());
sc.addBean(contract2);
sc.commit();
return true;
}
批刪
@RequestMapping("/dels")
@ResponseBody
public boolean dels(String ids,HttpServletRequest request) throws SolrServerException, IOException {
//mysql删除
as.dels(ids);
//solr删除
String[] split = ids.split(",");
List<String> list = Arrays.asList(split);
sc.deleteById(list);
sc.commit();
//静态网页批量删除
String path = request.getSession().getServletContext().getRealPath("/");
File file = new File(path+"/page/"+ids+".html");
file.delete();
return true;
}