Spring MVC Theme(简单示例)
在渲染视图的spring-web中,配置them。
实现两个接口就可以使用:
ResourceBundleThemeSource --> 用于确定要使用的主题的名字(theme name)
SessionThemeResolver --> 用于加载主题文件(通过 theme name)
这里默认加载default.properties的资源
<!--theme-->
<bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource">
<!--加载资源-->
<property name="basenamePrefix" value="theme."/>
</bean>
<!-- 【可选】 -->
<!-- 默认情况下,使用的是 FixedThemeResolver 来确定主题名字,默认名字为 theme -->
<!-- 可以根据实际情况配置为 SessionThemeResovler/CookieThemeResolver -->
<bean id="themeResolver" class="org.springframework.web.servlet.theme.SessionThemeResolver">
<!--默认主题文件的名字是 "xxxx",如果不设置,名为 theme-->
<property name="defaultThemeName" value="default"/>
</bean>
前端代码:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="<spring:theme code="main.body" />" >
</head>
<body>
<div>
一键切换主题:<br/>
<a href="/th/default">默认</a>
<a href="/th/boy">男孩</a>
<a href="/th/girl">女孩</a>
</div>
<br/>
<div>
人生,是风景和艰辛的组合,<br/> 欣赏路上风景的同时,<br/> 难免会遇上一个臭水沟,<br/> 但是不快总要度过,<br/> 与其心心念念它如何影响了你的心情,<br/> 不如快速跨过,<br/> 欣赏其他风景,<br/> 无论风景还是艰辛,<br/> 我们都要向前走。<br/>
</div>
</body>
</html>
后端代码:
package com.oukele.web; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ThemeResolver; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; @Controller
public class ThemeController { //将theme注入容器中
@Autowired
private ThemeResolver themeResolver; /**
* 返回一个页面
* */
@GetMapping(path = "/th")
public String getPage(){
return "theme1";
} /**
*请求方式:GET
* 参数:theme
* 请求url:/th/对应主题的文件
*/
@RequestMapping(path = "th/{theme}",method = RequestMethod.GET)
public String theme1(@PathVariable("theme") String themeStr,HttpServletRequest request,HttpServletResponse response){
themeResolver.setThemeName(request,response, themeStr);
return "redirect:/th";
} }
theme文件夹里的结构(里面有三个主题)
引用对应的css文件
运行结果:
默认主题:
男孩主题:
女孩主题:
新手笔记,大神路过请见谅。
Spring MVC Theme(简单示例)的更多相关文章
- MogliFS与spring mvc结合简单示例
一.MogliFS 与Spring结合配置请参照上文 二.上传页面 <%@ page language="java" contentType="text/html; ...
- Spring MVC之简单入门
一.Spring MVC简介: 1.什么是MVC 模型-视图-控制器(MVC)是一个众所周知的以设计界面应用程序为基础的设计模式.它主要通过分离模型(Model).视图(View)及控制器(Contr ...
- 用Spring MVC开发简单的Web应用程序
1 工具与环境 借助Eclipse4.3 + Maven3.0.3构建Java Web应用程序.使用Maven内置的servlet 容器jetty,不需手工集成Web服务器到Eclipse.还帮我们自 ...
- Spring MVC - Hello World示例
以下示例演示如何使用Spring MVC框架编写一个简单的基于Web的Hello World应用程序.首先使用Eclipse IDE,并按照以下步骤使用Spring Web Framework开发一个 ...
- 用Spring MVC开发简单的Web应用
这个例子是来自于Gary Mak等人写的Spring攻略(第二版)第八章Spring @MVC中的一个例子,在此以学习为目的进行记录. 问题:想用Spring MVC开发一个简单的Web应用, 学习这 ...
- Spring MVC 入门教程示例 (一)
今天和大家分享下 Spring MVC 入门教程 首先还是从 HelloWorld web 工程开始 -------------------------- 1.首先创建一个Maven Web工程 ...
- 基于注解的Spring MVC的简单入门——简略版
网上关于此教程各种版本,太多太多了,因为我之前没搭过框架,最近带着两个实习生,为了帮他们搭框架,我只好...惭愧啊...基本原理的话各位自己了解下,表示我自己从来没研究过Spring的源码,所以工作了 ...
- spring mvc 注解入门示例
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...
- spring boot thymeleaf简单示例
说实话,用起来很难受,但是人家官方推荐,咱得学 如果打成jar,这个就合适了,jsp需要容器支持 引入依赖 <dependency> <groupId>org.springfr ...
随机推荐
- 【VS开发】【Linux开发】【DSP开发】如何截获以太网帧并解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- icon.css
.icon-blank{ background:url('icons/blank.gif') no-repeat; } .icon-add{ background:url('icons/edit_ad ...
- CDH的mysql主从准备
参考: https://www.cnblogs.com/yinzhengjie/p/10371899.html https://www.sysit.cn/blog/post/sysit/CDH6.2. ...
- 西安邀请赛-E(树链剖分+线段树)
题目链接:https://nanti.jisuanke.com/t/39272 题意:给一棵树,n个结点,树根为1,n-1条边,每个结点有一个权值.进行3种操作: 1 s t:把1和s之间的最短路径上 ...
- ubuntu 18.04 配置notebook远程连接的坑
jupyter-notebook的安装不在此说明 在网上搜了很多方案都不行,好不容易从坑里爬出来 以下为远程连接配置方法 1.生成配置文件 jupyter notebook --generate-co ...
- 2019CCPC-江西省赛 -A Cotree (树形DP,求树上一点到其他点的距离之和)
我是傻逼我是傻逼 #include<bits/stdc++.h> using namespace std; const int maxn=4e5+50; typedef long long ...
- JavaScript Let 和 Const
来源:菜鸟教程:https://www.runoob.com/js/js-let-const.html JavaScript let 和 const ECMAScript 2015(ECMAScrip ...
- python并发编程-进程间通信-Queue队列使用-生产者消费者模型-线程理论-创建及对象属性方法-线程互斥锁-守护线程-02
目录 进程补充 进程通信前言 Queue队列的基本使用 通过Queue队列实现进程间通信(IPC机制) 生产者消费者模型 以做包子买包子为例实现当包子卖完了停止消费行为 线程 什么是线程 为什么要有线 ...
- 操作系统(五)CPU调度
CPU调度是多道程序操作系统的基础.
- javaagent项目中使用
相关代码参考:http://blog.csdn.net/catoop/article/details/51034778 近期项目中需要对SpringMVC中的Controller方法进行拦截做预处理, ...