EL expression use

The JSP EL expression obtains the number in the picture address in the database for calculation. In
recent projects, the mouse is required to move the product on the page to replace the picture of another color of the product.
The path of the picture in my database is
Insert picture description here
what I need to get to the picture address. Numbers are +1 because each of my pictures has three colors and the three color
pictures stored in my database are consecutive 1.jpg, 2.jpg, 3.jpg so I need to get the numbers in this string 1

Implementation method
1. Import jstl's own function jar package
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
2.
Idea 1
1.jpg Because of the number It is dynamic/repeated many times, so here we need to find a fixed and non-repeating substring,
that is, the subscript of .(dot) in 1.jpg
fn:indexOf(i.getSISBN(),".") -1 Here I am calling the EL expression indexOf method

Let's analyze the usage of this method below

fn:indexOf(string, the sub-character you are looking for) The first parameter is the parent string that needs to be searched for. The second parameter is the string contained in the parent string
fn:indexOf(i.getSISBN(),"." )-1
My first parameter is that the address of the picture stored in the collection is followed by the number. (dot) and -1 just finds the position of the number.
Idea 2 After
getting the subscript of the number, you can use fn: The substring method intercepts the number
${fn:substring(i.getSISBN(),
fn:indexOf(i.getSISBN(),".")-1,
fn:indexOf(i.getSISBN(),".")) }The
first parameter is the parent string. The second parameter is the starting point of the subscript in the parent string. The
third parameter is the end.
Finally, we can get the number. $(fn:substring(i.getSISBN(),
fn:indexOf(i.getSISBN(),".")-1,
fn:indexOf(i.getSISBN(),"."))+1} At the end, +1
will get the second color picture of the product

Guess you like

Origin blog.csdn.net/MyAzhe0ci3/article/details/108053237