Application.properties 中
#指定端口号
server.port=
#指定访问路径必须以/crud/xxx 开始
server.servlet.context-path=/crud
#指定编码格式
server.tomcat.uri-encoding=UTF-
#指定日期格式
spring.mvc.date-format=yyyy-MM-dd # 禁用缓存
spring.thymeleaf.cache=false # 国际化配置文件(包名.基础名)
spring.messages.basename=i18n.login

pom 文件中需要加上自己需要的依赖:如

    <!--引入jquery-webjar-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.</version>
</dependency> <!--引入bootstrap-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.0.</version>
</dependency>

静态页面不要放在静态文件夹下,会得不到模板引擎的解析需要放在

首先就是要访问我们的首页,这是可以指定的首先可以写一个方法这时有两种方法

(1)不推荐 在controller中写上一个方法

 @RequestMapping({"/","/index.html"})
public String index(){
//模板引擎会自动进行拼写自动加上.html
return "login";
}

(2)加上视图映射 viewControlle

手动写上一个配置类使用视图映射

因为WebMvcConfigurerAdapter 在Spring5.0已被废弃所以  博主推荐的两种方式https://blog.csdn.net/lenkvin/article/details/79482205

1 直接实现WebMvcConfigurer (官方推荐)

@Configuration
public class WebMvcConfg implements WebMvcConfigurer { //todo }

2 直接继承WebMvcConfigurationSupport

@Configuration
public class WebMvcConfg extends WebMvcConfigurationSupport { //todo }

使用第一种方法

说下默认映射的文件夹有:

classpath:/META-INF/resources

  • classpath:/resources

  • classpath:/static

  • classpath:/public

上面这几个都是静态资源的映射路径,优先级顺序为:META-INF/resources > resources > static > public

我们可以通过修改spring.mvc.static-path-pattern来修改默认的映射**

具体信息https://www.cnblogs.com/java-synchronized/p/7091723.html

对login.html 页面的修改

th:text是对标签体中的修改

th:text="#{login.password}

而复选框是字节数的没有标签体 所以使用

[[#{login.remember}]]

注册国际化标准i18N

别忘了在配置文件中加上

# 国际化配置文件(包名.基础名)
spring.messages.basename=i18n.login

放行静态资源

 registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/login.html","/","/webjars/**","/user/login","/static/**");

=====================================================================================================================================

 springboot的数据库的错误

当我使用springboot 的快速启动导入了jdbc  mybatis  出现这种错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
-- ::50.757 ERROR --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

《https://www.jianshu.com/p/836d455663da 解释详细连接》

问题原因: Mybatis没有找到合适的加载类,其实是大部分spring - datasource - url没有加载成功,分析原因如下所示.

  1. DataSourceAutoConfiguration会自动加载.

  2. 没有配置spring - datasource - url 属性.

  3. spring - datasource - url 配置的地址格式有问题.

  4. 配置 spring - datasource - url的文件没有加载.

方案一 (解决原因1)

排除此类的autoconfig。启动以后就可以正常运行。

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
方案二 (解决原因2)

在application.properties/或者application.yml文件中没有添加数据库配置信息.

spring:
datasource:
url: jdbc:mysql://localhost:3306/read_data?useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password:
driver-class-name: com.mysql.jdbc.Driver
方案三 (解决原因3)

在spring xml配置文件中引用了数据库地址 所以需要对:等进行转义处理.但是在application.properties/或者application.yml文件并不需要转义,错误和正确方法写在下面了.

//错误示例
spring.datasource.url = jdbc:mysql\://192.168.0.20\:1504/f_me?setUnicode=true&characterEncoding=utf8 //正确示例
spring.datasource.url = jdbc:mysql://192.168.0.20:1504/f_me?setUnicode=true&characterEncoding
方案四 (解决原因4)

yml或者properties文件没有被扫描到,需要在pom文件中<build></build>添加如下.来保证文件都能正常被扫描到并且加载成功.

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>

												

springboot 的部分细节的更多相关文章

  1. 简明易懂,将细节隐藏,面向新手树立web开发概念——学完Java基础语法,超快速上手springboot+mybatiJavaWeb开发

    简明易懂,将细节隐藏,面向新手树立web开发概念 --学完Java基础语法,超快速上手JavaWeb开发 Web本质(先忽视各种协议) Web应用可以理解为浏览器和服务器之间的交互. 我们可以看一个简 ...

  2. SpringBoot的学习【3.HelloWorld配置细节】

    /** * @SpringBootApplication用来标注主程序类. */ @SpringBootApplication public class First { public static v ...

  3. 【源码解析】自动配置的这些细节不知道,别说你会 springboot

    spring-boot 相对于 spring,很重要的一个特点就是自动配置,使约定大于配置思想成功落地.xxx-spring-boot-starter 一系列引导器能够开箱即用,或者只需要很少的配置( ...

  4. mybatis整合springboot 以及需要注意的细节

    具体怎么整合的网上有很多优秀的博客介绍,这里就直接引用一篇个人觉得非常详细的教程: https://blog.csdn.net/winter_chen001/article/details/77249 ...

  5. SpringBoot实例

    7player 7号球员 -- Show Time !跳至内容 首发 左边锋 技术流 外援 教练 7号 基于SpringBoot + Mybatis实现SpringMVC Web项目[原创] 目录 [ ...

  6. springboot 学习笔记(一)

    引子 最近在搞一个项目,走在科技前沿的师兄, 摒弃了公司老套的框架模式, 采用了springboot搭建新应用.看到如此简洁的代码 , 深受诱惑.趁周末闲余之时, 背晒阳光, 学起了springboo ...

  7. SpringBoot Quickstart

    SpringBoot Intro SpringBoot是顺应现在微服务(MicroServices)理念而产生的一个微框架(同类微框架可供选择的还有Dropwizard), 用来构建基于Spring框 ...

  8. 使用validator-api来验证spring-boot的参数

    作为服务端开发,验证前端传入的参数的合法性是一个必不可少的步骤,但是验证参数是一个基本上是一个体力活,而且冗余代码繁多,也影响代码的可阅读性,所以有没有一个比较优雅的方式来解决这个问题? 这么简单的问 ...

  9. springboot(十四):springboot整合shiro-登录认证和权限管理

    这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...

随机推荐

  1. offset系列,client系列,scroll系列回顾

    一 scroll系列属性      ——滚动

  2. java~使用自己的maven本地仓库

    本地仓库 主要是一种缓存,当你使用远程仓库中下载组件后,它下一次会优先从本地进行加载,一般位于USER_HOME/.m2目录下,我们自己也可以建立公用的包,把包发布到本地仓库,自己在其它项目里直接可以 ...

  3. 【带着canvas去流浪(8)】碰撞

    目录 一. canvas的能力 二. 动画框架 三. 在canvas中模拟碰撞 3.1定义小球的属性 3.2 生成新的小球 3.3 帧动画绘制函数step 3.4 定义小球的update方法 3.5 ...

  4. Tomcat 对 HTTP 协议的实现(下)

    在<Tomcat 对 HTTP 协议的实现(上)>一文中,对请求的解析进行了分析,接下来对 Tomcat 生成响应的设计和实现继续分析.本文首发于(微信公众号:顿悟源码) 一般 Servl ...

  5. 基于 DataLakeAnalytics 做跨地域的数据分析

    在阿里云上,很多客户的应用都是多地域部署的, 比如在北京(cn-beijing)的地域部署一个应用让北方的客户访问快一点,同时在杭州(cn-hangzhou)地域部署一份让南方的客户访问快一点.多地域 ...

  6. PyCharm出现TabError: inconsistent use of tabs and spaces in indentation最简单实用的解决办法

    本文使用PyCharm的格式化代码功能解决TabError: inconsistent use of tabs and spaces in indentation. 当把代码从别处复制进来PyChar ...

  7. FLASHBACK介绍

    在介绍flashback之前先介绍下undo_retention相关参数 undo_retention:表示undo数据的过期时间.系统默认这个时间设置为900即15分钟.但要注意,保证undo数据在 ...

  8. 【问题】VS问题集合,不用也要收藏防止以后使用找不到

    在日常的使用或者工作当中我们的vs会时不时的给我一些小“惊喜”.让我们有时候无可奈何.这不今天我又遇到了所以我决定记录下这些,方便以后再次出现好解决. 无法启动iis express web 服务器 ...

  9. 【译】.NET Core 3.0 中的新变化

    .NET Core 3.0 是 .NET Core 平台的下一主要版本.本文回顾了 .Net Core 发展历史,并展示了它是如何从基本支持 Web 和数据工作负载的版本 1,发展成为能够运行 Web ...

  10. npm --save-dev --save 的区别

    我们在使用npm install 安装模块或插件的时候,有两种命令把他们写入到 package.json 文件里面去,比如: --save-dev(-D) --save(-S) 在 package.j ...