<!-- freemarker + shiro(標籤) begin --> <dependency> <groupId>net.mingsoft</groupId> <artifactId>shiro-freemarker-tags</artifactId> <version>1.0.0</version> </dependency> <!-- freemarker + shiro(標籤) begin -->
import com.jagregory.shiro.freemarker.ShiroTags; import freemarker.template.TemplateModelException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import javax.annotation.PostConstruct; /** * @Author: SimonHu * @Date: 2020/6/8 17:02 * @Description: */ @Component public class ShiroTagsFreeMarkerCfg { private static final Logger log = LoggerFactory.getLogger(ShiroTagsFreeMarkerCfg.class); @Autowired private FreeMarkerConfigurer freeMarkerConfigurer; @PostConstruct public void setSharedVariable() throws TemplateModelException { log.info("設置freeMarker 的shiro 標籤"); freeMarkerConfigurer.getConfiguration().setSharedVariable("shiro", new ShiroTags()); } }
<!-- html 靜態頁面 -->
<div class="layui-side layui-side-bg layui-larry-side" id="larry-side"> <div class="layui-side-scroll" id="larry-nav-side" lay-filter="side"> <div class="user-photo"> <a class="img" title="我的頭像"><img src="http://api.zihexin.net/appimages/ad/20190702/17348339484_1080.png"></a> <p>你好!<span class="userName"><@shiro.principal property='username'/></span>, 歡迎登錄</p> </div> <!-- 左側菜單 --> <ul class="layui-nav layui-nav-tree"> <menu-item :item="item" v-for="item in menuList"></menu-item> </ul> </div> </div>