Upload pictures from the foreground and content into the database, and then read the content from the database, because it is related to the mobile Web page, so you need to set the width of the picture according to the screen size of the phone, I set here is 100%.
The backend controller code is as follows:
Import Org.jsoup.Jsoup;
Import org.jsoup.nodes.Document;
Document doc = Jsoup.parse (notice.getcontent ()); Convert the contents of notice into a jsoup string, which is equivalent to the content of the HTML page printed out by doc such as 1.
Doc.getelementsbytag ("img"). attr ("width", "100%"); Get the IMG tag, and set the property width to 100% printed out of doc like 2.
Notice.setcontent (Doc.tostring ()); Put Doc back in the content of notice to print out notice such as 3.
The jar package that needs to be imported:
Figure 1,doc is as follows: System.out.println (DOC);
<body>
</body>
Figure 2,doc is as follows: System.out.println (DOC);
<body>
</body>
The content of Figure 3,notice is as follows: System.out.println (notice.getcontent);
<body>
</body>
The complete controller method is as follows:
/**
* Jump to Public Notification Detail page
* @param request
* @return
*/
@RequestMapping ("/getnoticebyid")
Public String Getnoticebyid (HttpServletRequest request) {
int Noticeid = Integer.parseint (Request.getparameter ("Noticeid"));
1 Faculty Notice 2 Faculty Department notice 3 student Public Notice 4 Student Class Notice 5 student Department Notice
int flag = Integer.parseint (Request.getparameter ("flag"));
Notice Notice = null;
if (flag==1) {
Notice = Publicnoticeservice.findbyid (Noticeid);
Publicnoticeservice.addhittimes (Noticeid);
Request.setattribute ("title", "Public notice of Faculty and staff");
}else if (flag==2) {
Notice = Deptnoticeservice.findbyid (Noticeid);
Deptnoticeservice.addhittimes (Noticeid);
Request.setattribute ("title", "Public notice of Faculty and Staff Department");
}else if (flag==3) {
Notice = Stupublicnoticeservice.findbyid (Noticeid);
Stupublicnoticeservice.addhittimes (Noticeid);
Request.setattribute ("title", "Student Public notice");
}else if (flag==4) {
Notice = Stuclassnoticeservice.findbyid (Noticeid);
Stuclassnoticeservice.addhittimes (Noticeid);
Request.setattribute ("title", "Student class notice");
}else if (flag==5) {
Notice = Studeptnoticeservice.findbyid (Noticeid);
Studeptnoticeservice.addhittimes (Noticeid);
Request.setattribute ("title", "Student Department notice");
}
Document doc = Jsoup.parse (notice.getcontent ());
Doc.getelementsbytag ("img"). attr ("width", "100%");
Notice.setcontent (Doc.tostring ());
Request.setattribute ("notice", notice);
return "/plugins/mobileweb/web/views/notice/noticedetail";
}
Filter whether there is a picture in the content, and set the size of the picture