@RequestMapping("add")
public ModelAndView add(News news){
ModelAndView mav = new ModelAndView();
User u = new User();
u.setId(user.getId());
news.setUser(u);
String s = news.getContent();
String send="";
for(int i=1;i<=3;i++){
if(i!=1){
send=send+",";
}
int j=s.indexOf(file_server,i);//从file_server开始,i之后的。lastindexof中的i之前的
int j1=j+file_server.length();
String s1=s.substring(j1);
int l=s1.indexOf(".",i);
send=send+s.substring(j1, (j1+l+4));
}
news.setThumbnail(send);
news.setCreatetime(new Date());
OperationResult c = newsService.add(news);
mav.setViewName("knowledge/sharing/addnews");
return mav;
}
注意:file_server是本地服务器地址
最多传3张图片,放入for循环里面,循环截取src。存成缩略图