---------------------------------------------------------------------------
---------------------------------------------------------------------------
以下是java代码部分
---------------------------------------------------------------------------
@GET
@Path("loadGJCK")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@ApiOperation(value = "词库")
public String loadGJCK(@Context HttpServletRequest request,@Context HttpServletResponse response){
String result = "";
try {
StringBuilder sb = new StringBuilder();
String[] keywords = keywordService.selectKeyWord(10l);//获取所有分词,这里可以改进使用缓存等。
String eTag = request.getHeader("If-None-Match");
Long modified= request.getDateHeader("If-Modified-Since");
//设置头
if(null == modified || -1 == modified) {
//如果没有,则使用当前时间
modified = System.currentTimeMillis();
}
// 设置头信息。
String oldEtag = keywords.length+ "";
response.setDateHeader("Last-Modified", Long.valueOf(modified));
response.setHeader("ETags", keywords.length + "");
if(!oldEtag.equals(eTag)) {
//拼装结果
for(String tempWord : keywords) {
if(!StringUtils.isEmpty(tempWord)){
//分词之间以换行符连接
if(StringUtils.isNotEmpty(sb.toString())) {
sb.append("\r\n");
}
sb.append(tempWord);
}
}
//result = new String(result.getBytes("ISO8859-1"), "UTF-8");
result = sb.toString();
//更新时间
response.setDateHeader("Last-Modified", System.currentTimeMillis());
}
}catch (Exception e){
e.printStackTrace();
}finally {
System.out.println(result);
return result;
}
}
然后这个词库就可以用啦!