• 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>wonder</groupId>
        <artifactId>skyRainbow</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.3.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    创建程序启动入口文件

    package lf;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication // SpingBoot 相关注解,等于@Configuration、@EnableAutoConfiguration、@ComponentScan三个注解一起的作用
    public class SkyRainbowApplication {
    
        public static void main(String[] args) {
            /**
             * Spring boot 程序入口
             */
            SpringApplication.run(SkyRainbowApplication.class,args);
        }
    }

    创建相关类文件

    package lf.entity;
    
    
    public class SRUser {
    
        private String username;
    
        private String password;
    
        private String email;
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public String getEmail() {
            return email;
        }
    
        public void setEmail(String email) {
            this.email = email;
        }
    }
    package lf.controller;
    
    import lf.entity.SRUser;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller // 控制器注解
    @RequestMapping("/lf/user") 
    public class UserController {
    
        /**
         * 获取用户信息
         */
        @ResponseBody // 返回json数据的注解
        @RequestMapping(value = "/info",method = RequestMethod.GET)
        public SRUser getUserInfo(){
           SRUser user = new SRUser();
           user.setUsername("甘雨路");
           user.setPassword("123456");
           user.setEmail("1498222322@qq.com");
           return user;
        }
    
    }

    打开启动文件,并运行

     在浏览器上输入http://localhost:8080/lf/user/info 即可

     其中要注意启动文件要放在外层,否则无法自动扫描所有文件:

  • 相关阅读:
    ArcEngine实现对点、线、面的闪烁(转载)
    好久没写博客了.把这几个月的开发过程做一个总结
    利用暴力反编译的程序处理ArcXML数据遇到的问题小结(纯粹研究目的)
    ArcSde 9.2与Oracle 10g是最佳搭档
    当ArcEngine报事件同时存在于AxMapControl,MapControl时的解决方法(转载)
    写在苏州火炬接力的最后一站
    提问,如何才能触发鼠标事件
    地铁线路图高性能查找算法系统,最短路径查询地铁网络拓扑高效率算法原创附带demo
    二分查找
    .net面试题
  • 原文地址:https://www.cnblogs.com/lantu1989/p/8502635.html
Copyright © 2020-2023  润新知