Spring boot uploads pictures and displays them on the page and summarizes the problems encountered

Recently, in the process of building a website using spring boot, we encountered such a problem: when registering, users need to upload their own avatar. After successful registration, they jump to the personal center and display user information in the personal center There was a problem in displaying the Avatar: when uploading the avatar, I saved the avatar in the static folder under the project file, saved its address in the corresponding user in the database, and added a hot deployment in the idea, but I still couldn't display the avatar after registering and jumping to the personal center, Only when the next start-up project enters the personal center.

This problem has been bothered for a long time. Finally, the solution is as follows: create a webapp folder in the main directory and configure its path. The following is a small demo of the solution, which is relatively simple. Please forgive me ~ ~ the core code is as follows:

Registration interface:

Control is as follows:

Personal Center:

Configuration of webapp path

Corresponding user entity class:

Interface of user entity class:

The final operation is as follows:

Register to upload Avatar:

Personal Center:

PS: if spring security is combined, you only need to start from session SPRING_ Security_ CONTEXT. authentication. principal. Just get the information from XXX.

Attach the address of the uploaded Demo:

http://xiazai.jb51.net/201712/yuanma/demo5 (jb51.net). rar

summary

The above is a summary of the spring boot implementation of uploading pictures and displaying them on the page and the problems encountered. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>