spring boot 注意事项

1.项目启动的主类,放置位置在所有类的外层与controller,dao,service,util,entity同层,SpringBoot会自动扫描@SpringBootApplication所在类同级包。

@SpringBootApplication
public class Main {
public static void main(String[] args){
SpringApplication.run(Main.class, args);
}
}

2.WebMvcConfigurerAdapter中默认配置首页static/index.html

3.在通过url直接访问页面时,依赖thymeleaf模板引擎。若使用thymeleaf风格的html不需要配置InternalViewResolver,从SpringMVC转SpringBoot,不习惯这种html,需要在application.yaml中配置中央视图解析器

pom.xml中添加;

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

application.yaml 

在配置文件中加入ViewController中加入映射,便可访问/Resource/templates下的html文件:

4.在controller中使用@Controller,报错“template might not exist or might not be accessible by any of the configured Template Resolvers”。thymeleaf在返回view时模板解析失败。但我只是回去返回值,并不是渲染页面,将Controller改为RestController后,数据返回正常。

@RestController注解相当于@ResponseBody + @Controller合在一起的作用。

@RestController注解Controller,则Controller中的方法无法返回html页面,配置的视图解析器InternalResourceViewResolver不起作用,返回的内容就是Return 里的内容。

如果需要返回JSON,XML或自定义mediaType内容到页面,则需要在对应的方法上加上@ResponseBody注解。

SpringBoot点滴(1)的更多相关文章

  1. SpringBoot Quickstart

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

  2. 挖财大牛讲 Springboot工作流程

    转 Spring Boot Rock'n'Roll FuqiangWang - fujohnwang AT gmail DOTA com 2015-07-09 1 SpringBoot Intro 2 ...

  3. SpringBoot整合MyBatis例子

    1.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="h ...

  4. Docker系列-第七篇Docker构建SpringBoot应用

    1.基于Dockerfile构建SpringBoot镜像 1.1准备工作 将SpringBoot项目通过maven打成jar包 mvn clean package #使用maven打包项目 1.2使用 ...

  5. 解决 Springboot Unable to build Hibernate SessionFactory @Column命名不起作用

    问题: Springboot启动报错: Caused by: org.springframework.beans.factory.BeanCreationException: Error creati ...

  6. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo

    Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...

  7. Springboot搭建web项目

    最近因为项目需要接触了springboot,然后被其快速零配置的特点惊呆了.关于springboot相关的介绍我就不赘述了,大家自行百度google. 一.pom配置 首先,建立一个maven项目,修 ...

  8. Java——搭建自己的RESTful API服务器(SpringBoot、Groovy)

    这又是一篇JavaWeb相关的博客,内容涉及: SpringBoot:微框架,提供快速构建服务的功能 SpringMVC:Struts的替代者 MyBatis:数据库操作库 Groovy:能与Java ...

  9. 解决 SpringBoot 没有主清单属性

    问题:SpringBoot打包成jar后运行提示没有主清单属性 解决:补全maven中的bulid信息 <plugin> <groupId>org.springframewor ...

随机推荐

  1. cat & 文件结束符

    语法: 连接显示 选项: -n,显示行号. -v,显示不可见打印符. -E,显示“行结束符”($). 显示行号 $ cat -n /etc/fstab /dev/VolGroup00/LogVol00 ...

  2. uva-10026-贪心

    题意:有N项工作,每项工作完成需要n天,如果不开始做每天罚fee,开始做即不罚钱,求任务的执行顺序,使得罚钱最少.如果有多组答案,取下标排列最小的那组 解题思路: 考虑工作tn(dn,fn) , 假如 ...

  3. 25.纯 CSS 创作一个慧星拖尾效果的 loader 动画

    原文地址:https://segmentfault.com/a/1190000014916281 简化地址:https://codepen.io/pen/?editors=1100 HTML代码: & ...

  4. djangobb之debug-toolbar查看其sql

    #djangobb之views show_forum(request, forum_id, full=True) default queries including duplicates ) Quer ...

  5. mybatis中xml文件的${}和#{}区别

    之前的笔记:#{}相当于JDBC的? ${}是字符串连接符,如果入参为普通类型{}中只写value 在项目中要实现所有业务批量提交的功能,实现方式,把表名,表主键字段当做参数传递,在xml文件中全部使 ...

  6. react-native-vector-icons 图标库使用

    安装链接 yarn add react-native-vector-icons react-native link react-native-vector-icons 在项目工程中打开 .xcodep ...

  7. 机器学习进阶-图像基本操作-数值计算 1.cv2.add(将图片进行加和) 2.cv2.resize(图片的维度变换) 3.cv2.addWeighted(将图片按照公式进行重叠操作)

    1.cv2.add(dog_img, cat_img)  # 进行图片的加和 参数说明: cv2.add将两个图片进行加和,大于255的使用255计数 2.cv2.resize(img, (500, ...

  8. ubuntu oracle 环境搭建

    安装 Oracle SQL Developer Oracle客户端安装 https://oracle.github.io/odpi/doc/installation.html#linux

  9. Servlet基本_Httpリクエスト、レスポンス

    1.リクエスト リクエストは.リクエストライン.メッセージヘッダ.改行.メッセージボディで組まれる. 主なリクエストヘッダは. Accept クライアントが利用可能なデータメディアタイプを指定. Ac ...

  10. zabbix监控haproxy

    首先修改haproxy.cfg listen monitor_stat : stats uri /ihaproxy-stats stats realm Haproxy\ Statistics stat ...