Use of View and ViewResolver in Spring

xiaoxiao2021-03-06  54

Open Spring source code, we can see a lot of View and ViewResolver classes under org.springframework.web.servlet.view; the View class provides us with some default View, such as org.springframework.web. Servlet.view.Document.Abstract.AbstractExcelView provides a default view, org.springframework.web.servlet.view.Document.AbstractPdfview provides a default PDF format view; configuration through resource files and ViewResolver Use, we can show users our own style view.

There are several packages at org.springframework.web.servlet.view ViewResolver implemented, wherein the default configuration file using InternalResourceViewResolver such as:. org.springframework.web.servlet.view.jstlview / web-inf / jsp / .jsp The above configuration representation is based on the modelandview of the Controller returned, plus the directory prefix / Web-INF / JSP /, add file name suffix .jsp, thus waited for the next page such as /Web-inf/jsp/showcats.jsp

Another ViewResolver is ResourceBundleViewResolver, such as the configuration file as follows: views-countries < / value> Modelview baseName Configuration representation will get resources from the Views-Countries.properties file under the CLASSES directory In this way, we can easily achieve internationalization and localization; DefaultParentView means that all view will inherit from ModelView, which is similar to the log4j.

Other ViewResolver is the same as the above analysis.

转载请注明原文地址:https://www.9cbs.com/read-114548.html

New Post(0)