一、profile

        profile的功能就是来进行一套程序对开发,测试,生产等环境的动态配置切换

1.profile配置的两种方式:

1)多profile文件的方式

在sources中新建多个同类型的application文件,每个代表一种环境,开头名字都是“application”区别在于后面的备注例如application-dev(固定格式)

springboot No active springboot no active profile_html

2)yml当中多文档的方式

在yml中使用”---“分隔不同的配置

没两个---中的部分就是一个文档

springboot No active springboot no active profile_html_02

2.profile激活的方式

1)配置文件:在配置文件中配置:spring.profile.active=dev

2) 虚拟机参数

3)命令行参数

如果没有激活的话就会在日志中显示No active profile set, falling back to 1 default profile: "default"

springboot No active springboot no active profile_MVC_03

二、目录结构组成:

springboot No active springboot no active profile_spring_04

  • pom.xml:是项目中的Maven依赖,
  • application.properties: 编写Springboot与各框架整合的一些配置内容。
  • controller:用来编写控制器,主要负责处理请求以及和视图(Thymeleaf)绑定。
  • static:用于存放静态资源,例如html、JavaScript、css以及图片等。
  • templates:用来存放模板引擎Thymeleaf(本质依然是.html文件)

三、基础的实体类 

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.web.bind.annotation.PathVariable;

@RestController
public class controller {
    @GetMapping("/hello")//页面的url地址
    public String hello(){//对应的函数
        return "hello word";

    }

部分注释含义如下

  • @controller 注解的意思就是声明这个java文件为一个controller控制器。
  • @GetMapping(“index”) 其中@GetMapping的意思是请求的方式为get方式(即可通过浏览器直接请求),而里面的index表示这个页面(接口)的url地址(路径)。即在浏览器对项目网页访问的地址。
  • getindex() 是@GetMapping(“index”)注解对应的函数,其类型为String类型返回一个字符串,参数Model类型即用来储存数据供我们Thymeleaf页面使用。
  • model.addAttribute(“name”,“bigsai”) 就是Model存入数据的书写方式,Model是一个特殊的类,相当于维护一个Map一样,而Model中的数据通过controller层的关联绑定在view层(即Thymeleaf中)可以直接使用。
  • return “hello”:这个index就是在templates目录下对应模板(本次为Thymeleaf模板)的名称,即应该对应hello.html这个Thymeleaf文件(与页面关联默认规则为:templates目录下返回字符串.html)。

三、SpringMVC

 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写

 其三者在web项目中分工和职责不同,但又相互有联系。三者组成当今web项目较为流行的

MVC架构。

  • Model(模型)表示应用程序核心(用来存储数据供视图层渲染)。
  • View(视图)显示数据,而使用的Thymeleaf模板引擎就是在web中起到视图展示的作用。
  • Controller(控制器)处理输入请求,将模型和视图分离。