哈哈哈,还是在元旦这一天对你下手了。麻溜的给自己充电,在这个寒冬,不断听到裁员的消息或者新闻,可对于我这个外包和外派的人来说,好像并没有受到什么影响。可能是人手不够可能是项目很忙。对于明年的三月金四月银,我想在帝都,能有学习的时间还是要及时抓住,因为学习成本太高了。不罗嗦了,以后从帝都回去了再好好罗嗦。
SpringBoot入门学习参考:https://www.cnblogs.com/ityouknow/p/5662753.html
1、首先创建一个maven项目,创建过程如下所示:
2、然后添加maven依赖的jar包,如下所示:
<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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> </parent> <groupId>com.bie</groupId> <artifactId>spring-boot-hello</artifactId> <version>0.0.1-SNAPSHOT</version> <!-- 修改jdk版本,修改完jdk以后,更新项目,maven, Update Project--> <properties> <json.version>1.8</json.version> </properties> <dependencies> <!-- 注入spring boot的启动坐标 --> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web --> <!-- 注入spring boot的启动器 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
3、开发一个最简单的action,
1 package com.bie.action; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 6 import org.springframework.stereotype.Controller; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.ResponseBody; 9 10 /** 11 * 12 * @Description TODO 13 * @author biehl 14 * @Date 2018年12月22日 下午5:54:41 15 * 16 */ 17 @Controller 18 public class HelloWorld { 19 20 /** 21 * 22 * @return 23 */ 24 @RequestMapping("/hello") 25 @ResponseBody 26 public Map<String, Object> helloWorld() { 27 Map<String,Object> map = new HashMap<String, Object>(); 28 map.put("msg", "hello world SpringBoot !"); 29 return map; 30 } 31 32 }
4、书写一个SpringBoot的启动类。建议写代码的时候事先了解一下SpringBoot,这样帮助自己理解和学习。
package com.bie.action; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * * @Description TODO * @author biehl * @Date 2018年12月22日 下午7:39:50 * * 1、启动器类和项目同包不会出现问题。 * 平行包会出现问题。 */ @SpringBootApplication public class SpringBootMain { public static void main(String[] args) { //启动类 SpringApplication.run(SpringBootMain.class, args); } }
5、看看运行效果吧:
运行效果如下所示:
今天2018-12-24 18:33:42,祝大家平安夜快乐,不管过节不过节呢。都开开心心上班,及时充电。
待续......