SpringBoot学习笔记---SpringBoot基本配置

在这里插入图片描述

  • 示例:在classpath下创建application.properties文件
server.display-name=xmsApp
server.servlet-path=/
server.port=80

在这里插入图片描述

  • 示例:配置banner.txt文件
=============================================
=========大家好,我是xms======================
=========这是我的第一个Springboot程序============
==============================================
  • 启动容器时

在这里插入图片描述

在这里插入图片描述

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
</dependencies>
 
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <fork>true</fork>
            </configuration>
        </plugin>
    </plugins>
</build>
  • 开启热部署之后修改代码,会自动重启容器,但是重启容器的时间会大大减短,因为热部署只会重新加载被修改的文件.

在这里插入图片描述

在这里插入图片描述

  • 在控制器中使用@RestController注解配置,
  • @RequestMapping(value="/userid/{id}")注解定义了方法的映射路径,其中"{id}"为从路径上获取的内容,并将{id}获取到的内容,赋予方法的参数 id.
  • 对应的方法参数需要使用"@PathVariable "标明.
  • 示例:
@RequestMapping("/hello/{info}")
 public String echo(@PathVariable  String info){
     return "echo:"+info;
 }
  • 该方法将路径中{info}部分获取到并赋予方法参数"info"
  • 测试路径:
http://localhost/hello/rest风格路径测试
  • 此时会将/hello/路径后面部分的内容获取到,并传到方法之中,然后返回到页面之中.

在这里插入图片描述

在这里插入图片描述

  • 在类上使用@RestController注解表明该类使用Rest风格的url路径,并且所有方法均返回JSON数据.
  • 在类上使用@RequestMapping注解来定义访问该类的url映射路径为"/Student".
  • 如果要访问该类中的映射方法,则需要加上类上的映射路径,例如getStudent()方法上的@RequestMapping注解设置的映射路径为"/getStudent",该方法所属类的映射路径为"/Student",那么要访问getStudent()方法的url则为
ip地址:端口号/Student/getStudent
  • 示例:
package app.controllers;

import app.entity.Student;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value="/Student")
public class StudentController {
    @RequestMapping("/getStudent/name={name}")
    public Student getStudent(@PathVariable String name){
        Student student = new Student();
        student.setName(name);
        student.setSid(java.util.UUID.randomUUID().toString());
        return student;
    }
}

  • 测试访问路径
http://localhost/Student/getStudent/xms/22

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值