Application skin change - Summary

Keywords: Programming Session Database Thymeleaf JSP

(I) storage strategy

<1> database
You can add skin fields to the database user table for access. If the user table is not convenient for adding fields, you can add an intermediate table to store user and skin information.
< 2 > read write configuration
Users and skin information can be stored by reading and writing files.
<3>session
You can store skin information through session. After logging out, skin information will be reset.

(II) background logic implementation

//Store (set) skin code
public void saveNowSkin(@PathVariable("code") String code, @PathVariable("userId") String userId){
        SkinUserDto findSkinUserDto = skinUserClient.FindByUserId (userId);
        if(findSkinUserDto == null){
            SkinUserDto skinUserDto = new SkinUserDto ();
            skinUserDto.setUserId (userId);
            skinUserDto.setSkinCode (code);
            skinUserClient.add (skinUserDto);
        }else{
            findSkinUserDto.setSkinCode (code);
            skinUserClient.update (findSkinUserDto);
        }
    }
//Get skin information to the front end
request.getSession ().setAttribute ("nowSkin", getSkinCode ());

(III) front end implementation

<1>ThymeLeaf

<head>
    <title>Skin peeler</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="stylesheet" 
th:href="@{'/source/theme/'+${session.nowSkin==null?'default':session.nowSkin}+'/css/public.css'}"/>
</head>
//Set the skin to initiate a request through ajax, and refresh the page after the request succeeds
window.location.href = newUrl;

<2>JSP

<head>
    <title>Skin peeler</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link rel="stylesheet" 
href="'/source/theme/'+${session.nowSkin==null?'default':session.nowSkin}+'/css/public.css'"/>
</head>
//Set the skin to initiate a request through ajax, and refresh the page after the request succeeds
window.location.href = newUrl;

Posted by veronicabend on Thu, 07 Nov 2019 10:40:59 -0800