IDEA 集成的 Spring Boot 框架: thymeleaf + mysql + MyBatis +Druid +Redis + Maven + PageHelper (二)
前言
第一篇文章我们进行基本的数据分页展示。
现在我们将进行配置的是
- Lombok
- thymeleaf
Lombok是一种
Java™实用工具,可用来帮助开发人员消除 Java 的冗长,尤其是对于简单的 Java 对象(POJO)。它通过注解实现这一目的。
下面进行的是插件的安装:
-
首先我们需要安装IntelliJ IDEA中的lombok插件,打开IntelliJ IDEA后点击菜单栏中的File-->Settings,或者使用快捷键Ctrl+Alt+S进入到设置页面。
-
我们点击设置中的Plugins进行插件的安装,在右侧选择Browse repositories...,然后在搜索页面输入lombok变可以查询下方的Lombok Plugin,鼠标点击Lombok Plugin可在右侧看到Install按钮,点击该按钮便可安装。
-
我们在安装页面可以看到lombok具体支持的所有注解,在安装过程中有Downloading Plugins的提示,安装过程中进度条会变化。需要提醒的是,在安装过程中一定要保证网络连接可用且良好,否则可能会安装失败。安装成功后我们可以看到右侧的Restart按钮,此时可先不操作,因为我们还有后续的配置工作。安装完成后我们再回到Plugins,此时在右侧可以搜索到lombok,而安装前是不行的。
END
配置注解处理器
同样我们在Settings设置页面,我们点击Build,Execution,Deployment-->选择Compiler-->选中Annotation Processors,然后在右侧勾选Enable annotation processing即可。
lombok插件的使用
-
1 使用前我们需要说明的是安装的插件只是一个调用,就像我们使用maven插件一样,本机需要安装maven才行。我们在使用lombok前也需要添加lombok的依赖。lombok的版本一直在更新,大家可以在百度搜索框输入lombok maven找到最新的依赖版本。
[code] <!--lombok--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
-
2 接下来我们编辑一个实体类Student,添加三个属性,最后在类上添加@Data属性,这个注解可以帮我们在.class文件中生成类中所有属性的get/set方法、equals、canEqual、hashCode、toString方法等。
-
3 那么编辑完代码后我们如何查看生成的方法呢?在菜单栏点击View-->Tool Windows-->Structure,便可以看到类中所有的方法了,这些都是lombok帮我自动生成的。
END
注意事项
-
安装lombok插件过程中需要联网,另外安装需要配置Annotation Processors支持。
下面我们进行thymeleaf 配置
首先我们需要引入pom.xml文件
[code] <!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
application.properties的配置:
[code]##### thymeleaf #### spring.thymeleaf.prefix=classpath:/templates/ spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.cache=false spring.thymeleaf.suffix=.html spring.thymeleaf.mode=LEGACYHTML5 spring.resources.chain.strategy.content.enabled=true spring.resources.chain.strategy.content.paths=/**
controll:
[code] @RequestMapping("/getname") private String getname(Model model) { model.addAttribute("name","zhy"); return "user"; }
html页面:
[code]<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <p th:text="'Hello!' + ${name} + '!'">3333</p> </body> </html>
请求:
http://localhost:8080/user/getname
- intellij idea + spring boot + mybatis + druid + maven + mysql + thymeleaf
- maven+spring boot+druid+mysql+mybatis+pagehelper+jsp环境搭建
- Spring Boot : 集成mybatis、pagehelper插件、开启事务、druid数据源配置、mybatis-generator(十一)
- intellij idea + spring boot + spring data jpa + druid + maven + mysql + thymeleaf
- spring boot +Thymeleaf+mybatis 集成通用PageHelper,做分页
- IDEA搭建SpringBoot+Maven+Mybatis+MySQL-Web项目流程
- Spring,SpringBoot 集成 MyBatis 的分页插件 PageHelper
- SpringBoot_thymeleaf_mybatis和PageHelper分页插件整合
- Springboot+mybaties+pagehelper+thymeleaf+layui+maven搭建项目
- Spring Boot成长之路 02 - MySql + MyBatis + 通用Mapper + PageHelper
- Spring Boot系列六 Spring boot集成mybatis、分页插件pagehelper
- springboot2.0.5集成mybatis(PageHelper分页插件、generator插件使用)
- SpringBoot集成MyBatis的分页插件PageHelper(回头草)
- spring boot 简单集成 mybatis、druid(阿里巴巴连接池)、redis、jpa
- SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
- SpringBoot + MyBatis + DRUID + MySQL Maven依赖配置
- SpringBoot+Mybatis+ Druid+PageHelper 实现多数据源并分页
- springboot 2.0 集成mybatis,mybatis-generator,pagehelper
- springboot 集成myBatis PageHelper 分页插件
- spring-boot 集成mybatis的分页插件PageHelper和Generator