• spring-boot集成1:起步


    Why spring-boot?

    1. 创建独立的Spring应用程序
    2. 嵌入的Tomcat,Jetty和Undertow,无需部署WAR文件
    3. 通过starter依赖,简化Maven配置
    4. 自动配置Spring,以习惯大于配置的约定,减少样板配置
    5. 提供生产就绪型功能,如指标,健康检查和外部配置
    6. 绝对没有代码生成并且对XML也没有配置要求
     
    只需要极少的配置即可直接开发并运行一个spring应用
     

    1.配置spring-boot依赖

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.zhya</groupId>
        <artifactId>zhya-monocase-framework</artifactId>
        <version>1.0</version>
    
        <properties>
            <mapper.version>3.4.0</mapper.version>
            <maven.compile.source>1.8</maven.compile.source>
            <maven.compile.target>1.8</maven.compile.target>
        </properties>
    
        <!--parent中设置spring-boot版本号-->
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.0.0.RELEASE</version>
            <relativePath/>
        </parent>
    
        <dependencies>
            <!--spring boot web 开启web功能,启动时将直接运行web容器-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
        </dependencies>
    </project>
    

      

    2.启动类

    package com.zhya;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    /**
    * 启动类
    *
    * @Author zhangyang
    * @Date 下午 8:23 2018/11/20 0020
    **/
    @SpringBootApplication
    public class MonocaseFrameworkApplication {
    public static void main(String[] args) {
    SpringApplication.run(MonocaseFrameworkApplication.class, args);
    System.out.println("-------MonocaseFrameworkApplication started-------");
    }
    } 
     

    3.配置文件

    application.yml

    spring:
    application:
    name: monocase-framework # 应用名称
    jackson:
    date-format: yyyy-MM-dd HH:mm:ss # 日期格式


    server:
    port: 8090 # 端口

      

     

    4.rest接口

    package com.zhya.controller;
    
    import com.zhya.entity.SysUser;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.util.Date;
    
    /**
     * 系统用户controller
     *
     * @Author zhangyang
     * @Date 下午 8:31 2018/11/20 0020
     **/
    @RestController
    @RequestMapping("sysuser")
    public class SysUserController {
    
        /**
         * 获取单个系统用户
         *
         * @Author zhangyang
         * @Date 下午 8:31 2018/11/20 0020
         **/
        @GetMapping("/{id}")
        public SysUser test(@PathVariable String id) {
            // FIXME for testing
            return new SysUser(id, "zhya", new Date(), new Date());
        }
    
    }
    

    5.运行&测试

    启动

    访问接口

  • 相关阅读:
    爬虫心得
    WSL windows子系统ubuntu18.04建设自己的乌云
    WSL windwos 子系统 ubuntu18.04安装mysql
    python 163 email 554
    Centos 安装Oracle
    JS带进度 文件 重复 自动 异步上传
    xadmin 小组件默认折叠
    grep
    sed
    awk
  • 原文地址:https://www.cnblogs.com/zhya/p/9989839.html
Copyright © 2020-2023  润新知