在淘宝、京东等电商网站,其门户网站都有一个商品品类的多级联动,鼠标移动,就显示,因为前端不是我做的,所以不说明前端实现,只介绍后端实现。
搭建部署SpringBoot环境
配置文件配置:
开启了对Thymeleaf模块引擎的支持
server: port: 8081 #logging: # config: classpath:logback_spring.xml # level: # com.muses.taoshop: debug # path: /data/logs spring: datasource: # 主数据源 shop: url: jdbc:mysql://127.0.0.1:3306/taoshop?autoReconnect=true&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false username: root password: root driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource # 连接池设置 druid: initial-size: 5 min-idle: 5 max-active: 20 # 配置获取连接等待超时的时间 max-wait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 time-between-eviction-runs-millis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 min-evictable-idle-time-millis: 300000 # Oracle请使用select 1 from dual validation-query: SELECT 'x' test-while-idle: true test-on-borrow: false test-on-return: false # 打开PSCache,并且指定每个连接上PSCache的大小 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 filters: stat,wall,slf4j # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 合并多个DruidDataSource的监控数据 use-global-data-source-stat: true # jpa: # database: mysql # hibernate: # show_sql: true # format_sql: true # ddl-auto: none # naming: # physical-strategy: org.hibernate.boot.entity.naming.PhysicalNamingStrategyStandardImpl # mvc: # view: # prefix: /WEB-INF/jsp/ # suffix: .jsp #添加Thymeleaf配置 thymeleaf: cache: false prefix: classpath:/templates/ suffix: .html mode: HTML5 encoding: UTF-8 content-type: text/html #Jedis配置 # jedis : # pool : # host : 127.0.0.1 # port : 6379 # password : redispassword # timeout : 0 # config : # maxTotal : 100 # maxIdle : 10 # maxWaitMillis : 100000 SpringBoot启动类:
package com.muses.taoshop; import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.cache.annotation.EnableCaching; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.stereotype.*; import org.springframework.t
