Tomcat相关配置
在代码中进行配置
@Component
public class CustomServletContainer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.setPort(8080);
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,"/404.html"));
container.setSessionTimeout(10, TimeUnit.MINUTES);
}
}
这里EmbeddedServletContainerCustomizer、ConfigurableEmbeddedServletContainer在springboot 2.0.2版本中是找不到的
需要把
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
改成
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
引用thymeleaf需要在配置文档中配置好不然无法访问到templates下面
#thymeleaf 关闭缓存 spring.thymeleaf.cache=false spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.suffix=.html spring.thymeleaf.mode=HTML5 server.tomcat.access_log_enabled=false server.tomcat.basedir=target/tomcat
学到的
bootstrap一点点样式框架
@RequestMapping("/")
public String index(Model model) {
Person single = new Person("aa", 11);
List<Person> people = new ArrayList<>();
Person p1 = new Person("zhangsan", 11);
Person p2 = new Person("lisi", 22);
Person p3 = new Person("wangwu", 33);
people.add(p1);
people.add(p2);
people.add(p3);
model.addAttribute("singlePerson", single);
model.addAttribute("people", people);
return "index";
}
在入口类中添加如下代码,可以由后台向前台页面返回两条数据,
一个单个的Person对象,还有一个people对象是一个List集合,集合中放了3个Person对象,
到时候我们直接将这两条数据在html页面上显示出来
关于html页面
th:each="person:${people}"
表示遍历people中的元素
th:οnclick="'getName(\''+${person.name}+'\');'" 表示添加点击事件,点击事件由JavaScript来处理
th:inline="javascript"
这样添加到的script标签可以通过[[${singlePerson}]]
访问model中的属性。
学习博客地址:https://blog.csdn.net/u012702547/article/details/53784992