2020.09 问题总结(Oracle-->MySQL、Maven、JSP-->Thymeleaf、Druid)

2020.09 问题总结(Oracle-->MySQL、Maven、JSP-->Thymeleaf、Druid)

数据库建表

Oracle 转 MySQL 问题

Oracle MySQL
可变字符 varchar2 varchar
自增id default SYS_GUID() CREATE TRIGGER product_before_insert BEFORE INSERT ON product FOR EACH ROW
BEGIN
IF new.id is NULL THEN
SET new.id = UUID();
END IF;
END;
字符串转timestamp to_timestamp('10-10-2018 10:10:00.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), TIMESTAMP('2018-12-25 10:18:00.000000')

Maven模块化构建工程

The POM for com.food:food-manager-pojo:jar:0.0.1-SNAPSHOOT is missing, no dependency informat

搭建完所有子工程后,在Maven父工程处,点击install完成工程构建:

image-202009251jgfhfghfghg53110095

Thymeleaf 替换 JSP

超链接及静态资源使用:

<!-- 超链接: -->
<a th:href="@{/pages/main}">
<!--静态资源: -->
<img th:src="@{/img/center.jpg}">

重用模板片段:

image-20200925154240878

提取模板片段作为单个页面(不同于JSP不提取也是可以的)

<html xmlns:th="http://www.thymeleaf.org">

<!-- 页面头部 -->
<header class="main-header" th:fragment="header">
    ...
    </header>
</html>
<html xmlns:th="http://www.thymeleaf.org">
    <!-- 导航侧栏 -->
<aside class="main-sidebar" th:fragment="aside">
    ...
    </aside>
</html>

需要使用模板片段的,

  • 采用th:insert的方法
<!-- 页面头部 -->
		<div th:insert="~{pages/header.html::header}"></div>
			<!-- 页面头部 /-->

		<!-- 导航侧栏 -->
		<div th:insert="~{pages/aside.html::aside}"></div>
  • 还可以使用th:replaceth:include属性插入。

image-20200925183319097

文本输入

<span th:text="This is prototype text002.">This is prototype text.</span>

使用变量

<span th:text="${userName}">This is prototype text.</span>

迭代器

image-20200927191513411

整合 Druid 数据源

SQL监控和SQL防火墙无信息原因及解决方法

原因:

没有开启Filterstatwall)配置。

以下开启方法将会开启失败:

datasource:
    ...
    # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,
    #'wall'用于防火墙
    filters: stat,wall

解决办法:

druid:
      filter:
        stat:
          enabled: true
        wall:
          enabled: true

开启后在数据源filter类名中可以查看到statwall的类名。(未开启之前是为空的)

image-20200925194904326

具体配置如下:

spring:
  datasource:
   # driver-class-name: com.mysql.cj.jdbc.Driver   #
    type: com.alibaba.druid.pool.DruidDataSource

    druid:
      url: jdbc:mysql://localhost:3306/tams_bg?serverTimezone=UTC
      username: root
      password: 123456
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,
      #'wall'用于防火墙
      filter:
        stat:
          enabled: true
        wall:
          enabled: true
      # 配置StatFilter
      web-stat-filter:
        #默认为false,设置为true启动
        enabled: true
        exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
      #配置StatViewServlet
      stat-view-servlet:
        url-pattern: "/druid/*"
        #允许那些ip
        login-username: tom001
        login-password: 1234
        #禁止那些ip
        deny: 192.168.1.102
        #是否可以重置
        reset-enable: true
        #启用
        enabled: true
      #最大等待时间,配置获取连接等待超时,时间单位都是毫秒ms
      max-wait: 60000
      #最大值
      max-active: 20
      #最小值
      min-idle: 5
      #初始化大小
      initial-size: 5
      #配置一个连接在池中最小生存的时间
      min-evictable-idle-time-millis: 60000
      #配置间隔多久才进行一次检测,检测需要关闭的空闲连接
      time-between-eviction-runs-millis: 300000
      test-on-borrow: false
      test-on-return: false
      test-while-idle: true
      pool-prepared-statements: true
      #最大PSCache连接
      max-pool-prepared-statement-per-connection-size: 20
      use-global-data-source-stat: true
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

posted @ 2020-10-02 09:25  L1ng14  阅读(252)  评论(0编辑  收藏  举报