springBoot_demo
pom文件:
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>com.sophia</groupId> 8 <artifactId>springboot</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>war</packaging> 11 12 <parent> 13 <groupId>org.springframework.boot</groupId> 14 <artifactId>spring-boot-starter-parent</artifactId> 15 <version>2.0.2.RELEASE</version> 16 </parent> 17 18 <name>springboot Maven Webapp</name> 19 <!-- FIXME change it to the project's website --> 20 <url>http://www.example.com</url> 21 22 <properties> 23 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 24 <maven.compiler.source>1.8</maven.compiler.source> 25 <maven.compiler.target>1.8</maven.compiler.target> 26 </properties> 27 28 <dependencies> 29 <dependency> 30 <groupId>junit</groupId> 31 <artifactId>junit</artifactId> 32 <version>4.11</version> 33 <scope>test</scope> 34 </dependency> 35 36 <!--springBoot启动包--> 37 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> 38 <dependency> 39 <groupId>org.springframework.boot</groupId> 40 <artifactId>spring-boot-starter-web</artifactId> 41 <version>2.0.2.RELEASE</version> 42 </dependency> 43 <!--springBoot实现热部署所需要的包--> 44 <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools --> 45 <dependency> 46 <groupId>org.springframework.boot</groupId> 47 <artifactId>spring-boot-devtools</artifactId> 48 <optional>true</optional> 49 <version>2.0.2.RELEASE</version> 50 </dependency> 51 </dependencies> 52 53 <build> 54 <finalName>springboot</finalName> 55 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 56 <plugins> 57 <plugin> 58 <artifactId>maven-clean-plugin</artifactId> 59 <version>3.0.0</version> 60 </plugin> 61 <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> 62 <plugin> 63 <artifactId>maven-resources-plugin</artifactId> 64 <version>3.0.2</version> 65 </plugin> 66 <plugin> 67 <artifactId>maven-compiler-plugin</artifactId> 68 <version>3.7.0</version> 69 </plugin> 70 <plugin> 71 <artifactId>maven-surefire-plugin</artifactId> 72 <version>2.20.1</version> 73 </plugin> 74 <plugin> 75 <artifactId>maven-war-plugin</artifactId> 76 <version>3.2.0</version> 77 </plugin> 78 <plugin> 79 <artifactId>maven-install-plugin</artifactId> 80 <version>2.5.2</version> 81 </plugin> 82 <plugin> 83 <artifactId>maven-deploy-plugin</artifactId> 84 <version>2.8.2</version> 85 </plugin> 86 <!--tomcat插件--> 87 <!--<plugin>--> 88 <!--<groupId>org.apache.tomcat.maven</groupId>--> 89 <!--<artifactId>tomcat7-maven-plugin</artifactId>--> 90 <!--<version>2.2</version>--> 91 <!--<configuration>--> 92 <!--<path>/</path>--> 93 <!--<port>8080</port>--> 94 <!--<server>tomcat7</server>--> 95 <!--</configuration>--> 96 <!--<executions>--> 97 <!--<execution>--> 98 <!--<phase>package</phase>--> 99 <!--<goals>--> 100 <!--<goal>run</goal>--> 101 <!--</goals>--> 102 <!--</execution>--> 103 <!--</executions>--> 104 <!--</plugin>--> 105 106 <!-- maven热部署插件 --> 107 <plugin> 108 <groupId>org.springframework.boot</groupId> 109 <artifactId>spring-boot-maven-plugin</artifactId> 110 <configuration> 111 <fork>true</fork> 112 </configuration> 113 </plugin> 114 </plugins> 115 </pluginManagement> 116 </build> 117 </project>
启动java类:
1 package com.bee.sample.ch1; 2 3 import org.springframework.boot.SpringApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6 @SpringBootApplication 7 public class Ch1Application { 8 public static void main(String[] args) { 9 SpringApplication.run(Ch1Application.class); 10 } 11 }
controller类:
1 package com.bee.sample.ch1.controller; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.ResponseBody; 6 7 @Controller 8 public class HelloworldController { 9 @RequestMapping("/sayhello.html") 10 public @ResponseBody 11 String say() { 12 return "hello spring boot---"; 13 } 14 }
rest风格:
1 package com.bee.sample.ch1.controller; 2 3 import org.springframework.web.bind.annotation.PathVariable; 4 import org.springframework.web.bind.annotation.RequestMapping; 5 import org.springframework.web.bind.annotation.RestController; 6 7 @RestController 8 public class UserReditRestController { 9 @RequestMapping(value = "/usercredit/{id}") 10 public String getCreditLevel(@PathVariable String id) { 11 return id; 12 } 13 }
idea热部署:

crtl+alt+shift+/


浙公网安备 33010602011771号