MySQL获取时间差
DATEDIFF函数只可以计算天数
SQL语句:
1SELECT DATEDIFF ("2021-04-25 23:23:12","2021-04-21 23:23:12") AS days;
结果:
TIMESTAMPDIFF函数可以根据自己的需求计算天数、小时、分钟、秒钟
SQL语句:
1234SELECT TIMESTAMPDIFF (DAY,"2021-04-21 23:23:12","2021-04-25 23:23:12") AS "天";SELECT TIMESTAMPDIFF (HOUR,"2021-04-21 23:23:12","2021-04-25 23:23:12") AS "时";SELECT TIMESTAMPDIFF (MINUTE,"2021-04-21 23:23:12","2021-04-25 23:23:12") AS "分"; ...
HTML+JavaScript动态获取当前时间
HTML代码12<p id="tipForTime" style="color: #00B0E8;text-align: center"></p><p>当前时间: <span id="time" style="color: grey"></span></p>
JavaScript代码12345678910111213141516171819202122232425262728293031323334353637//获取当前时间window.onload = function () { window.requestAnimationFrame(getDate)}function getDate() { window.setTimeout(function () { window.requestAnimationFrame(getDate) }, 1000 / 2) v ...
一套绝佳的图标字体库和CSS框架:Font Awesome图标
概述Font Awesome是一套绝佳的图标字体库和CSS框架。
Font Awesome字体为您提供可缩放矢量图标,它可以被定制大小、颜色、阴影以及任何可以用CSS的样式。
引入1<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
使用1<i class="fa fa-car"></i>
代码12345678910111213<!DOCTYPE html><html><head><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css"></head><body> <i class="f ...
highlight.js实现代码高亮
引入更换代码样式直接修改link标签的css文件名,例如:将androidstudio改为github就行了,更多样式名称查看:highlight.js代码样式名称
123<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/androidstudio.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script><script>hljs.initHighlightingOnLoad();</script>
代码块外围代码code标签的class内填代码类型,不填也可以,会自动检测
12345<pre> <code class="HTML"> ...
MyBatis的关联(association)元素
关联(association)元素处理“有一个”类型的关系。 比如,在示例中,每个博客有一个作者
1234567<resultMap id="blogResult" type="Blog"> <association property="author" column="author_id" javaType="Author" select="selectAuthor"/></resultMap> <select id="selectAuthor" resultType="Author"> SELECT * FROM AUTHOR WHERE ID = #{id}</select>
MyBatis动态SQL示例
if123456789101112131415161718192021222324252627<select id="list" parameterType="map" resultMap="BlogResult"> select * from t_blog <where> <if test="title != null and title != ''"> and title like #{title} </if> <if test="blogTypeId != null"> and blogTypeId = #{blogTypeId} </if> <if test="isMenuBlog != null"> and isMenuBlog = #{isMenuBlog} </i ...
MyBatis的增删改查示例(XML映射器)
增加123<insert id="add" parameterType="BlogType"> insert into t_blogtype (name, sortNum) values (#{name},#{sortNum});</insert>
删除123<delete id="delete" parameterType="integer"> delete from t_blogtype where id=#{id}</delete>
修改123456789101112<update id="update" parameterType="BlogType"> update t_blogtype <set> <if test="name != null and name != ''"& ...
MyBatis的结果映射
结果映射的作用resultMap 元素是 MyBatis 中最重要最强大的元素。它可以让你从 90% 的 JDBC ResultSets 数据提取代码中解放出来,并在一些情形下允许你进行一些 JDBC 不支持的操作。实际上,在为一些比如连接的复杂语句编写映射代码的时候,一份 resultMap 能够代替实现同等功能的数千行代码。ResultMap 的设计思想是,对简单的语句做到零配置,对于复杂一点的语句,只需要描述语句之间的关系就行了
代码实体类(已经省略getter和setter方法)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778package com.ledao.entity; import java.util.Date; /** * 博客实体 * * @author LeDao * @company * @create 2020-09 ...
MyBatis的元素属性
Select
值
作用
id
在命名空间中唯一的标识符,可以被用来引用这条语句。
parameterType
将会传入这条语句的参数的类全限定名或别名。这个属性是可选的,因为 MyBatis 可以通过类型处理器(TypeHandler)推断出具体传入语句的参数,默认值为未设置(unset)。
resultType
期望从这条语句中返回结果的类全限定名或别名。 注意,如果返回的是集合,那应该设置为集合包含的类型,而不是集合本身的类型。 resultType 和 resultMap 之间只能同时使用一个。
resultMap
对外部 resultMap 的命名引用。结果映射是 MyBatis 最强大的特性,如果你对其理解透彻,许多复杂的映射问题都能迎刃而解。 resultType 和 resultMap 之间只能同时使用一个。
flushCache
这是一个给驱动的建议值,尝试让驱动程序每次批量返回的结果行数等于这个设置值。 默认值为未设置(unset)(依赖驱动)。
useCache
将其设置为 true 后,将会导致本条语句的结果被二级缓存缓存起来,默认值 ...
Spring Boot引入MyBatis
引入依赖12345<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version></dependency>
application.yml配置12345678#mybatis的相关配置mybatis: #mapper配置文件 mapper-locations: classpath:mybatis/mapper/*.xml type-aliases-package: com.ledao.entity #开启驼峰命名 configuration: map-underscore-to-camel-case: true
加入@MapperScan注解在项目的启动类中加入@MapperScan注解,这样就可以指定要扫描的Mapper类的包的路径了
项目代码示例以对一个博客类进行操 ...