使用Spring Boot开发Web项目遇到的问题



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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值