zoukankan      html  css  js  c++  java
  • spring boot +maven+ thymeleaf+mysql 第一个spring boot实例总结

    spring boot 基础入门:

    1.参考 CSDN博客:http://blog.csdn.net/ityouknow/article/details/70053058

    2.在IDEA下搭建maven环境:参考博客:http://blog.csdn.net/u013248535/article/details/55100979

    3.实例参考:https://gitee.com/jeff1993/springboot-learning-example/commit/ea647045dc4e9c626aa0d90664459d7bdce305a2

    4.pom文件配置:

       1)添加spring-boot-starter-data-jpa ,参考博客:http://blog.csdn.net/yingxiake/article/details/51016234

       

    2)添加mysql的依赖:

     3)添加thymeleaf依赖

     4)spring boot  parent版本为2.0.0.M4

    5)编码:UTF-8;JDK 1.8

    5.application.properties配置:

    1)配置mysql及hibernate:(本地搭建mysql服务器及客户端)

    #mysql must put here
    #mysql连接
    spring.datasource.url:jdbc:mysql://192.168.39.7:3306/demo?characterEncoding=utf-8
    spring.datasource.username=root
    spring.datasource.password=chenzx0918

    spring.datasource.sql-script-encoding=utf-8
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.test-on-borrow=true
    spring.datasource.validation-query= select 1
    spring.datasource.max-active=100
    spring.datasource.max-wait=10000
    spring.datasource.min-idle=10
    spring.datasource.time-between-eviction-runs-millis= 5000
    spring.datasource.min-evictable-idle-time-millis=30000
    spring.datasource.test-while-idle=true
    spring.datasource.test-on-return=false

    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.hibernate.namingStrategy=org.hibernate.cfg.DefaultNamingStrategy
    spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect
    ## 是否显示 SQL 语句
    spring.jpa.show-sql=true

    2)thymeleaf   配置:

    thymeleaf 详情使用参考:https://www.tianmaying.com/tutorial/using-thymeleaf

     调试过程中遇到的问题:

    1)由于  spring boot parent 版本造成经常报错,在pom中升级版本后解决了一部分问题

    2)代码中定义Logger类,由于import错误的类,导致程序报错

     spring boot 默认使用Logback 来记录日志,并用INFO级别输出到控制台,但是查看了依赖包后,发现有slf4j的依赖包,所以引入类时,应引用:

    import org.slf4j.Logger;//Logback是log4j框架的作者开发的新一代日志框架,它效率更高、能够适应诸多的运行环境,同时天然支持SLF4J。
    import org.slf4j.LoggerFactory;



    错误是由于引入java.util.logging 造成的,修改为slf4j就正常了。可参考csdn博客:https://www.cnblogs.com/zheting/p/6707041.html

    调代码时一定要仔细看报错及报错原因,采用逐一排查法,逐一注释掉代码进行排查。

  • 相关阅读:
    移动端开发rem布局之less+媒体查询布局的原理步骤和心得
    前端实现文件下载方式总汇
    如何能提高CSS编写技巧?提高Web前端开发效率
    常用的CSS命名规则
    CSS背景background
    CSS盒子模型
    简单的树形菜单如何写?
    彻底掌握css动画【transition】
    首页白屏优化实践
    我来聊聊面向模板的前端开发
  • 原文地址:https://www.cnblogs.com/jshtest/p/8427078.html
Copyright © 2011-2022 走看看