In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use Springboot to play jar package thymeleaf, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Springboot is packed into jar package thymeleaf1. Use springboot to pack into jar packages
Need to add plug-ins to maven
Org.springframework.boot spring-boot-maven-plugin true org.apache.maven.plugins maven-compiler-plugin 1.7 1.7 BOOT-INF/lib/ ${basedir} / lib/ * * / .jar ${basedir} / src/main/java BOOT-INF/classes/ True * * / * .xml * * / * .properties src/main/java * * / * .xml false 2. Controller Write / * Jump to the case data upload page * / @ GetMapping ("to_case") public String jumpToCase (Map map) {map.put ("name") "General specialist case data") Return "/ case";}
This form is OK locally, but if you pack it into jar, you will not find the case.html page, which actually exists.
It needs to be modified to:
Return "case"
Or change it to:
/ * Jump to the case data upload page * / @ GetMapping ("to_case") public ModelAndView jumpToCase (Map map) {map.put ("name", "full specialist case data"); return new ModelAndView ("case");}
Both of these methods are OK, and you can jump by typing it into a jar package again.
When the springboot + thymeleaf jar package runs, it reports an error. You should know how to arrange the error like this.
Recently in the use of springboot+thymeleaf technology, packaged as a jar package when running always report 500errors, so write down some common reasons below for your reference.
Error code picture: and the page does not return anything, only 500 error codes are prompted. Only in the log can you see the error log.
After the final success of the test:
1. Static file error
For example, if the static css,js file of bootstrap or layui is not found, the following error will be reported
Org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/main.h tml]")
You will find that there is no indication that the page does not exist, that is, the thymeleaf error, so at this point we have to wonder if the static file did not find the troubleshooting process:
1.1 whether the path to the js file is correct or not
I will use layui's static resource file and bootstrap's static resource file to demonstrate respectively.
Layui: directly on the path map
Next, I will give the file location of the project and the method of referencing the layui style for your reference.
Error prone point 1: use relative paths
Remember! Never use relative paths. The code I annotated can only be run locally, but not for packaging and uploading, so follow my example and write the following code
Error prone point 2: use thymeleaf templates but not th:href
I was trapped here, which can be run locally, but uploaded to the server to run.
Bootstrap:
Is the 1.2:thymeleaf template referenced correctly
Note that, for example, referencing a written template should be referenced as follows:
The above sentence is wrong because it can be deleted by adding an extra /.
Summary: if you do not use the corresponding method to reference thymeleaf as required, it is very easy to have my error log above, and will return a 500 error code.
The 2.controller layer returns a page error
Common error tips:
You can't find the file you should go to under the templates page (since you can only write this kind of bug at the beginning, you can't find a picture to post)
This problem is easy to solve. First of all, check to see if the jump is correct under controller:
Remember not to add the "/" slash in front of the path. If you run under the cloud server, you will definitely report a 500 error and you can't find this page.
Thank you for reading this article carefully. I hope the article "how to use Springboot to make a jar package thymeleaf" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.