zoukankan      html  css  js  c++  java
  • SpringBoot学习helloworld

      这几天开始学习springBoot记录一下(Hello World)

       
         pom.xml

     1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     3     <modelVersion>4.0.0</modelVersion>
     4     <groupId>org.bianqi.spring.first</groupId>
     5     <artifactId>SpringBootFirst</artifactId>
     6     <version>0.0.1-SNAPSHOT</version>
     7     <packaging>war</packaging>
     8     <parent>
     9         <groupId>org.springframework.boot</groupId>
    10         <artifactId>spring-boot-starter-parent</artifactId>
    11         <version>1.4.1.RELEASE</version>
    12     </parent>
    13     <dependencies>
    14         <dependency>
    15             <groupId>org.springframework.boot</groupId>
    16             <artifactId>spring-boot-starter-web</artifactId>
    17         </dependency>
    18     </dependencies>
    19     <build>
    20         <plugins>
    21             <plugin>
    22                 <groupId>org.apache.maven.plugins</groupId>
    23                 <artifactId>maven-compiler-plugin</artifactId>
    24                 <configuration>
    25                     <source>1.7</source>
    26                     <target>1.7</target>
    27                 </configuration>
    28             </plugin>
    29             <plugin>
    30                 <groupId>org.springframework.boot</groupId>
    31                 <artifactId>spring-boot-maven-plugin</artifactId>
    32                 <configuration>
    33                     <mainClass>${start-class}</mainClass>
    34                     <layout>ZIP</layout>
    35                 </configuration>
    36                 <executions>
    37                     <execution>
    38                         <goals>
    39                             <goal>repackage</goal>
    40                         </goals>
    41                     </execution>
    42                 </executions>
    43         </plugin>
    44         </plugins>
    45     </build>
    46 </project>

         2.编写controller

     1 package org.bianqi.first.demo;
     2 
     3 import org.springframework.beans.factory.annotation.Autowired;
     4 import org.springframework.boot.SpringApplication;
     5 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
     6 import org.springframework.context.annotation.ComponentScan;
     7 import org.springframework.web.bind.annotation.RequestMapping;
     8 import org.springframework.web.bind.annotation.RestController;
     9 
    10 @RestController
    11 @EnableAutoConfiguration
    12 @ComponentScan
    13 public class FirstDemo {
    14     
    15     @Autowired
    16     private FirstService fs;
    17     
    18     @RequestMapping("/")
    19     String home(){
    20         fs.demo();
    21         return "hello world!";
    22     }
    23     public static void main(String[] args) {
    24         SpringApplication.run(FirstDemo.class, args);
    25     }
    26     
    27 }

    3.编写service的接口

    1 package org.bianqi.first.demo;
    2 
    3 public interface FirstService {
    4   public String demo();
    5 }

    4.编写service层实现类

     1 package org.bianqi.first.demo;
     2 
     3 import org.springframework.stereotype.Service;
     4 
     5 @Service
     6 public class FirstServiceImpl implements FirstService{
     7 
     8     public String demo(){
     9         System.out.println("hhhhh");
    10         return "helloworld我爱你";
    11     }
    12 }

    在Controller中通过main方法启动~浏览器访问http://localhost:8080/ 显示helloworld 并且控制台打印hhhhh

  • 相关阅读:
    js 比较日期的大小
    日历(从今天起后面的14天)
    数字转大写
    object对象进行深拷贝
    浏览器渲染机制
    t-5.倒计时(秒杀效果)--本地--服务器(待续)
    s-1.rem自适应
    t-3.跑马灯
    t-2.手机端简单轮播(无滑动效果)
    16.弹性布局
  • 原文地址:https://www.cnblogs.com/bianqi/p/6411690.html
Copyright © 2011-2022 走看看