Filter whether there is a picture in the content, and set the size of the picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.