react-router版本 v4.x
跟着官网 https://reacttraining.com/react-router/ 上的example学习的
<Router>
<header>
<ul>
<li><Link to='/home'>Home</Link</li>
<li><Link to='/about'>About</Link</li>
<li><Link to='/login'>Login</Link</li>
<li><Link to='/register'>Register</Link</li>
</ul>
</header>
<section>
<Route path='/home' component={Home}/>
<Route path='/about' component={About}/>
<Route path='/login' component={Login}/>
<Route path='/register' component={Register}/>
</section>
<footer>
balabalabala...
</footer>
</Router>
spring-boot 使用 spring-security 博客 https://kielczewski.eu/2014/12/spring-boot-security-application/
web项目在启动之后有时候还会做点其它的东西(比如,导入数据脚本),下面就说说spring-boot里怎么在程序启动后加入自己要执行的东西
新建一个类:BeforeStartup.java
@Configuration
public class BeforeStartup implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private InitDB initDB;
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
initDB.createUser();
}
}
网上搜索到的都是用thymeleaf模板做的国际化,没找到freemarker,然后我想到了,spring-boot 用的mvc框架不就是springmvc吗,然后就搜索了下springmvc freemarker i18n,结果还真让我找到了
spring:
messages:
basename: i18n/messages
在src/main/resources下新建文件夹i18n
在i18n文件夹里创建文件messages.properties、messages_en_US.properties
创建模板
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
</head>
<body>
<div id="box"></div>
<script type="text/template" id="tpl">
hello, <%=name%>
</script>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script src="//cdn.bootcss.com/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript">
var name = 'world';
var render = _.template($("#tpl").html());
$("#box").html(render({name: name}));
</script>
</body>
</html>