thymeleaf

Spring Boot 访问静态资源

霸气de小男生 提交于 2020-05-09 13:32:26
在SpringBoot 项目中没有我们之前常规web 开发的WebContent(WebApp),它只有 src 目录。在src/main/resources 下面有两个文件夹,static 和templates。SpringBoot 默认在static 目录中存放静态页面,而templates 中放动态页面。 1 static 目录 Spring Boot 通过classpath/static 目录访问静态资源。注意存放静态资源的目录名称必须 是static。 2 templates 目录 在Spring Boot 中不推荐使用jsp 作为视图层技术,而是默认使用Thymeleaf 来做动态页 面。Templates 目录这是存放Thymeleaf 的页面。 来源: oschina 链接: https://my.oschina.net/u/4292686/blog/4271712

springboot bootstrap和thymeleaf的使用

跟風遠走 提交于 2020-05-08 20:33:11
最近想用springboot自己用业余时间写一个网站,发现坑很多,遇到很多问题,包括前端和后端,前端的基础太不扎实了,还有很多内容需要进一步学习。 这里转一篇bootstrap和thymeleaf在springboot的使用 Spring Boot项目的默认模板引擎是Thymeleaf,这没什么好说的,个人觉得也非常好,因为这款引擎可以前后端同时开发,类似 th:xxx 这样的内联标签属性会被html5无情忽视,所以前台在开发静态页面的时候就正常开发,正常预览,后台拿来开发好的模板加上这个标签分分钟就开始用,这也是这个引擎的最大好处(你把后台jsp页面在浏览器直接打开就知道这是什么意思了)。 bootstrap作为老牌前台框架,有大量开发好的优秀模板(尤其是各种admin模板),拿来就能用。但是最近在试图把网上下载的一套开源bootstrap模板整合到thymeleaf时遇到一些小问题,经过查阅资料最后解决了,记录一下。 这个问题就是,当你把前台模板直接copy到工程中(css/js/img等直接放在resources/static文件夹下,页面放在resources/templates下),类似这样: Paste_Image.png login.html中加一句话变成thymeleaf模板 <!DOCTYPE html> < html xmlns:th= "http://www

【SpringBoot】转载 springboot使用thymeleaf完成数据的页面展示

為{幸葍}努か 提交于 2020-05-08 20:32:55
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/weixin_36380516/article/details/78668199 上一篇介绍了使用jsp完成数据的页面展示 ,但是springboot并不推荐使用jsp,会产生很多问题。官方推荐使用thymeleaf,这里我们将上一篇的jsp页面展示修改为使用thymeleaf,通过对比来熟悉thymeleaf,其实改动的地方并不大。 第一篇springboot入门时介绍了项目的大致结构,当时图省事所有的类都放在一个包中,这里略做调整,然后再resource下新建文件夹存放thymeleaf模板,使用springboot生成工程时应该会默认有这几个文件夹,此时项目结构大致如下: 为thymeleaf添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 查询接口(接上一篇,基本没变) /** * @return * 查询全部信息 */ @RequestMapping("/list") public ModelAndView

Spring Boot Security

徘徊边缘 提交于 2020-05-08 19:41:59
如图,是一种通用的用户权限模型。一般情况下会有5张表,分别是:用户表,角色表,权限表,用户角色关系表,角色权限对应表。 一般,资源分配时是基于角色的(即,资源访问权限赋给角色,用户通过角色进而拥有权限);而访问资源的时候是基于资源权限去进行授权判断的。 Spring Security和Apache Shiro是两个应用比较多的权限管理框架。Spring Security依赖Spring,其功能强大,相对于Shiro而言学习难度稍大一些。 Spring的强大是不言而喻的,可扩展性也很强,强大到用Spring家族的产品只要按照其推荐的做法来就非常非常简单,否则,自己去整合过程可能会很痛苦。 目前,我们项目是基于Spring Boot的,而且Spring Boot的权限管理也是推荐使用Spring Security的,所以再难也是要学习的。 Spring Security简介 Spring Security致力于为Java应用提供认证和授权管理。它是一个强大的,高度自定义的认证和访问控制框架。 具体介绍参见https://docs.spring.io/spring-security/site/docs/5.0.5.RELEASE/reference/htmlsingle/ 这句话包括两个关键词: Authentication(认证) 和 Authorization(授权,也叫访问控制)

springboot的thymeleaf模板中input, select, radio回显

不羁岁月 提交于 2020-05-08 19:26:14
input的: <input type="text" class="form-control1" id="name" name="name" th:value="${user.name}"> select的: <label class="col-sm-2 control-label">类别</label> <div class="col-sm-8"> <select name="cId" id="cId" class="form-control1" > <option value="1" th:field="*{book.cId}">目录1</option> <option value="2" th:field="*{book.cId}">目录2</option> <option value="3" th:field="*{book.cId}">目录3</option> <option value="4" th:field="*{book.cId}">目录4</option> </select> </div> radio的: <label for="isBoy" class="col-sm-2 control-label">是否男生</label> <div id="isBoy" class="col-sm-8"> <div class="radio-inline"> <label

axios学习--起步

跟風遠走 提交于 2020-05-08 09:46:11
官网: http://www.axios-js.com/zh-cn/docs/ 什么是 axios? Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。 特性 从浏览器中创建 XMLHttpRequests 从 node.js 创建 http 请求 支持 Promise API 拦截请求和响应 转换请求数据和响应数据 取消请求 自动转换 JSON 数据 客户端支持防御 XSRF 安装   使用 npm: $ npm install axios   使用 cdn: < script src ="https://unpkg.com/axios/dist/axios.min.js" ></ script > demo: <! DOCTYPE html > < html xmlns:th ="http://www.thymeleaf.org" > < head > < meta charset ="UTF-8" > < title > Title </ title > < script src ="https://unpkg.com/axios/dist/axios.min.js" ></ script > </ head > < body > < p id ="p" ></ p > < script > //get axios. get (

springboot整合Redis

倖福魔咒の 提交于 2020-05-08 00:48:04
1、新建项目,并添加所需要的jar包: 分析: (1)在springboot中已经继承了Redis,就是说一旦我们启动项目,它是可以根据properties配置文件中的配置信息自动创建Jedis对象的 (2)我们想要的是自己定义配置信息的名称,再根据自己定义的配置信息配置一个有关配置信息的类,最后根据这个类来创建一个我们想要的Jedis对象。 (3)springboot项目在加载的时候,由于springboot无法从配置文件中获取想要的信息,所以不会自动创建属于springboot的Jedis对象,而是根据我们自定义 的配置信息进行创建一个Jedis对象 (4)在使用Jedis对象的时候,我们给我们的Jedis对象加上了@Bean注解,在要使用Jedis的类中使用@Autowired注解,所以spring中的BeanFactory工厂自动创建对象, ,且是单例的;此处直接在@Autowire的注解下注入的是(3)中的对象,也就是根据我们自定义信息创建的对象 springboot-parent spring-boot-web-start mysql驱动包 druid(德鲁伊)连接池 springboot和mybatis的整合包 thymeleaf模板jar包 thymeleaf忽略语法的jar包 springboot和redis的整合包 jedis的包:

laypage 物理分页与逻辑分页实例

你离开我真会死。 提交于 2020-05-07 20:06:38
前言   以下介绍摘自 layui官网laypage   layPage 致力于提供极致的分页逻辑,既可轻松胜任异步分页,也可作为页面刷新式分页。自 layui 2.0 开始,无论是从核心代码还是API设计,layPage 都完成了一次蜕变。清爽的UI、灵活的排版,极简的调用方式,这一切的优质元素,都将毫无违和感地镶嵌在你的页面之中。laypage 的使用非常简单,指向一个用于存放分页的容器,通过服务端得到一些初始值,即可完成分页渲染,laypage 只负责分页本身的逻辑,具体的数据请求与渲染需要另外去完成。laypage 不仅能应用在一般的异步分页上,还可直接对一段已知数据进行分页展现,更可以取代传统的超链接分页。 效果 代码编写   项目背景:springboot + springdata-jpa + thymeleaf + mysql   代码贴出来:同样的,大部分逻辑都写在了注释里面   maven引包 <!-- springboot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot<

Controller中的方法如何返回到HTML页面+Form表单提交到Controller的路径问题+properties的中文乱码问题

我是研究僧i 提交于 2020-05-07 02:59:07
1 Controller中的方法如何返回到HTML页面:   首先Controller: @Controller Public class TestController{ @RequestMapping(value ="/form" ) public String aa(){ return "qq" ; } } 配置文件application.yml: //path之后的路径是html页面的位置 spring.thymeleaf.preifx:classpath:/templates/ .html是要切换到的html的后缀 spring.thymeleaf.suffix:.html  qq.html: < form action ="form" method ="post" > dsadas </ form > 注意这是springboot+gradle项目,一定要引入thymeleaf的依赖。 2 Form表单提交到Controller的路径问题   controller中的RequestMapping("/form"),而如果html页面的form表单action的路径为/***,这个/是针对web服务器的根目录,而不是项目的根目录,可以看下发送url请求,没有项目名称,如果form表单提交的时候没有进入controller的方法

20200505

你离开我真会死。 提交于 2020-05-05 23:57:39
java springboot配置thymeleaf模板引擎 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> 来源: oschina 链接: https://my.oschina.net/shenGuangYue/blog/4267650