SpringBoot(2)前端

前一篇SpringBoot初步主要涉及后端代码,这一篇主要是记录一下springBoot中的前端知识。
1、thymeleaf
看网上好多使用thymeleaf模板构建springBoot前端,索性也尝试了一下。
先在static目录下放了张图片,浏览器中可以访问。
然后再templates目录下创建了个hello.html静态资源文件

application.properties中增加配置

#thymeleaf模板配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=utf-8
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**

此时浏览器中访问不到,经查找原因,在配置文件中又新增一下配置

#dev tools
spring.devtools.livereload.enabled=true
# 静态文件请求匹配方式
spring.mvc.static-path-pattern=/**
# 修改默认的静态寻址资源目录
spring.resources.static-locations = classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

再次访问成功。此时理解为:网上直接增加thymeleaf配置就可以的例子,是动态资源,我加的是静态资源,所以访问时报404的错。后来增加的是静态资源配置。(待更新)

2、ajax前端请求
实现功能:增加页面,使用jquery.ajax()向后端传递请求,并将后台获取的数据渲染至页面列表(调用users用户列表接口)。

过程中主要问题为jquery.ajax()方法以及后台对于入参和出参处理。

前端

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Springboot + Jsp</title>
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值