基于SpringBoot2.x + layui2.5.x + Thymeleaf + Mysql5.7 版本开发的后台管理系统
springDataJpa动态代理扩展
给所有的DAO接口添加相同的默认方法:
https://blog.csdn.net/weixin_45138931/article/details/102979230
https://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-adding-custom-methods-into-all-repositories/
JPA 通过@Query和JPQL分页查询
//JPQL
@Query(value = "SELECT u FROM User u ORDER BY id")
Page<User> findAllUsersWithPagination(Pageable pageable);
// Native
@Query(
value = "SELECT * FROM Users ORDER BY id",
countQuery = "SELECT count(*) FROM Users",
nativeQuery = true)
Page<User> findAllUsersWithPagination(Pageable pageable);
Mysql 5.7 创建create_time和update_time字段自动更新
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更新时间',
JPA 存在updateTime字段时,更新Entity对象,如果updateTime为Null,会导致数据库不自动更新update_time字段,并设置成NULL
@EnableJpaAuditing
@SpringBootApplication
public class Springboot2DemoApplication {}
// @LastModifiedDate 自动设置updateTime
@Column(name = "update_time")
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat
@LastModifiedDate
private Date updateTime;
Ignoring null Parameters Using the @Query Annotation
@Query("SELECT c FROM Customer c WHERE (:name is null or c.name = :name) and (:email is null"
+ " or c.email = :email)")
List<Customer> findCustomerByNameAndEmail(@Param("name") String name, @Param("email") String email);
HTML通过flex实现左右DIV布局
<div style="display: flex;
flex-flow: row nowrap;
justify-content: space-between;">
<div>left</div>
<div>right</div>
</div>
thymeleaf th:href添加URL参数
<a th:href="@{/index(param1='value1',param2='value2')}">
thymeleaf 获取当前Request中的参数、Session参数 somesite.com/login?error=true
<div id="errors" th:if="${(param.error != null) and (param.error[0] == 'true')}">
Input is incorrect
</div>
session params
${session.foo} // Retrieves the session atttribute 'foo'
${session.size()}
${session.isEmpty()}
${session.containsKey('foo')}
thymeleaf Null 安全
<td th:text="${user?.address?.city}"></td>
<span th:text="${object.property} ? 'this is good' : 'default value'"></span>
<span th:text="${object.property} ?: 'default value'"></span>
thymeleaf 字符串isEmpty判断
${#strings.isEmpty(name)}
// is true if name is not empty
${!#strings.isEmpty(name)} or ${not #strings.isEmpty(name)}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。