LMLPHP后院

Java jdbc Mysql datetime 多个 .0技术

maybe yes 发表于 2017-07-18 10:25

数据库字段为 datetime 类型,Java 中 Entity 使用 String 类型,选出的数据后面会包含 ".0",有人说是由于 MySQL datetime 是包含毫秒的。如下时间格式:

2017-07-12 18:08:02.0

一个不太文雅的解决方案,简单粗暴。

public String getCreateTimeStr() {
    if (create_time == null) {
        return "";
    }
    return create_time.substring(0, create_time.length() - 2);
}

不知道那些 Java 高手是怎么做的,欢迎评论。

Spring Boot Jpa 使用原生 SQL 和动态分页技术

maybe yes 发表于 2017-07-15 11:30

使用 Jpa 分页报个错:

Cannot use native queries with dynamic sorting and/or pagination in method public abstract org.springframework.data.domain.Page

Jpa 的原生 SQL 对命名没有严格的要求,如下示例:

package com.lmlphp.test;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.repository.query.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface TestRepository extends JpaRepository<Test, Long> {

    @Query(
            value="select * from table_name where status=:status \n#pageable\n",
            countQuery = "select count(*) from table_name where status=:status",
            nativeQuery=true)
    Page<Test> findByStatus(@Param("status") int status, Pageable pageable);
}

class 连写提升 CSS 样式优先级技术

maybe yes 发表于 2017-07-12 20:34

本文介绍一些前端技巧,前端高手可以绕道。

平时在写 CSS 的时候,经常的会用到 @media screen 功能,用来兼容不同设备。在实际测试中发现,@media screen 样式必须放在被覆盖的样式后面,否则这个样式是不会生效的。

当今很流行的网页布局,左边菜单区,位置固定,主体内容区域除去菜单区域宽度后居中展示;如果屏幕比较小,对主体内容样式做一些修改,比如与左边菜单区的距离等。如下代码示例:

.sidebar {
    position: fixed;
    z-index: 10;
    top: 100px;
    left: 0;
    bottom: 0;
    padding: 40px 0 30px 30px;
    width: 260px;
    margin-right: 20px;
    overflow-x: hidden;
    overflow-y: auto;
}

.content {
    position: relative;
    padding: 2.2em;
    margin: 0 auto;
    margin-left: 300px;
}

@media screen and (max-width: 1500px){
    .content {
        margin-left: 280px;
    }
}

is marked as crashed and last (automatic?) repair failed技术

maybe yes 发表于 2017-07-08 09:05

MYSQL MyISAM 数据表出现问题,提示 Error: Table './db_name/table_name' is marked as crashed and last (automatic?) repair failed。

修复数据表操作:

  • 1. service mysqld stop;
  • 2. cd /var/lib/mysql/db_name/
  • 3. myisamchk -r table_name.MYI (修复单张数据表), myisamchk -r *.MYI (修复所有数据表)
  • 4. mysqlcheck -o -r db_name -p

查看 warning 信息:

解决 Discontiguous selection is not supported技术

maybe yes 发表于 2017-07-07 11:17

chrome 浏览器是不支持不连续的 selection 的,通篇只能有一个,目前估计只有 Firefox 是例外的吧。不支持是能理解的,因为光标也是一个特殊的选区,而光标同一时刻只能有一个。

要解决这个报错,只能在选择之前,移除所有选区。做过编辑器的人应该深有体会吧!

selection.removeAllRanges();
saveSelection.addRange(range);
2024-04-23 16:11:32 1713859892 0.019875