• SpringBoot的使用


    一、Maven的环境搭建

            暂时未完成....

    二、创建项目

     

     

     

     创建完以后的目录如下:

     然后配置pom.xml

    再放入配置项

    1. nexus-aliyun
    2. Nexus aliyun
    3. http://maven.aliyun.com/nexus/content/groups/public
    4. org.springframework.boot
    5. spring-boot-starter-parent
    6. 1.4.0.RELEASE
    7. org.springframework.boot
    8. spring-boot-devtools
    9. true
    10. org.springframework.boot
    11. spring-boot-starter-thymeleaf
    12. maven-compiler-plugin
    13. 2.3.2
    14. 1.8
    15. 1.8
    16. UTF-8
    17. org.springframework.boot
    18. spring-boot-maven-plugin

    再右键-->Mavent-->Update更新

     选中当前项目

    三、 文件热部署

    1.application.properties参数配置      

    里面加上——spring.devtools.restart.enabled=true

    server.port=8081(改启动端口号为8081)

    2.在pom.xml中改为一下信息(上面的应该是已经改过的)

    1. 依赖包
    2. org.springframework.boot
    3. spring-boot-devtools
    4. true
    5. maven-compiler-plugin
    6. 2.3.2
    7. 1.8
    8. 1.8
    9. UTF-8
    10. org.springframework.boot
    11. spring-boot-maven-plugin
    12. 配置上去 即可

    四、配置启动项

    1.新建文件 ApplicationBootController 

    2.加入如下配置

    1. package boot;
    2. import org.springframework.boot.SpringApplication;
    3. import org.springframework.boot.autoconfigure.SpringBootApplication;
    4. import org.springframework.context.annotation.ComponentScan;
    5. //声明为启动类
    6. @SpringBootApplication
    7. /**
    8. * 管理包下所有的Component注解,包含Component的子注解,比如Service,Controller等
    9. */
    10. @ComponentScan(basePackages = { "com.tledu.kx" })
    11. public class ApplicationBootController {
    12. public static void main(String[] args) {
    13. SpringApplication.run(ApplicationBootController.class, args);
    14. }
    15. }

     注意:@ComponentScan(basePackages = { "里面为要管理的文件夹的名字" })

    3.在要控制的文件类上面都要加上 @Controller 这样才能被启动类监听到

    1. package com.tledu.kx;
    2. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    3. import org.springframework.stereotype.Controller;
    4. import org.springframework.web.bind.annotation.CrossOrigin;
    5. import org.springframework.web.bind.annotation.RequestMapping;
    6. import org.springframework.web.bind.annotation.RequestMethod;
    7. import org.springframework.web.bind.annotation.ResponseBody;
    8. @Controller
    9. @EnableAutoConfiguration
    10. public class kx_1 {
    11. // 请求的地址
    12. @RequestMapping(value = "/userDemo1", method = RequestMethod.GET)
    13. @ResponseBody
    14. // 解决跨域
    15. @CrossOrigin
    16. public void add(){
    17. System.out.println("--------------11111---------");
    18. }
    19. }

  • 相关阅读:
    STM32 GPIO的几种工作模式
    Spring Data MongoDB 使用
    点云 3D 数据 读取、保存 - pypcd 包
    华硕主板开启核显
    PHP语言基础知识,电商API代码生成
    Java面向对象七大原则以及设计模式单例模式和工厂模式简单工厂模式
    IPv6 中 MAC 33:33 的由来
    「MACOS限定」 如何将文件上传到GitHub仓库
    JavaScript快速入门
    logback--基础--05--配置--encoder
  • 原文地址:https://blog.csdn.net/gkx19898993699/article/details/127936701