https://maven.apache.org/download.cgi
解压并配置环境变量
检查是否配置成功 mvn -version
创建本地仓库,在已解压的lib同级目录下创建空文件夹maven-repo
修改设置文件settings.xml文件,全选文字crtl+f搜索localRepository
修改路径
阿里云镜像配置,在settings.xml 文件中找到mirrors节点,在该节点中插入如下代码
aliyunmaven
*
阿里云公共仓库
https://maven.aliyun.com/repository/public
配置JDK ,在settings.xml配置文件中找到profiles,在该节点中插入如下代码
jdk18
true
1.8
1.8
1.8
1.8
配置完成,win+R 运行 cmd ,输入mvn help:system 测试,如果本地仓库出现一些 文件,则说明配置成功。
.mvn
.gitignore
HELP.md
mvnw
mvnw.cmd
Application.java:程序入口。不能放包里,
查看文章http://t.csdnimg.cn/8GRun
查看文章:http://t.csdnimg.cn/xo1Js
package com.example.controller;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/books")
public class BookController {
@GetMapping("/{id}")
public String getById(@PathVariable Integer id){
System.out.println("id ==> "+id);
return "hello , spring boot!";
}
}
@GetMapping(“/test”)
等价于
@RequestMapping(value = “/test”,method = RequestMethod.GET)
@RequestMapping(value="/product/{id}",method=RequestMethod.GET)
public int getProduct(@PathVariable int id){
System.out.println(id);
return id;
}
@RequestMapping("/addUser")
public String addUser(String username){
return username;
}
//http://localhost:7777/addUser?username=tom
@RequestMapping("/addUser")
public String addUser(HttpServletRequest request){
return request.getParameter("username");
}
//127.0.0.1:8080/getforpara?goodsId=1&name=tom
@RequestMapping(value = "/getforpara")
public Map<String, Object> getGoods(@RequestParam(value = "goodsId", required = false, defaultValue = "11") int goodsId, @RequestParam String name) {
JSONObject goods = new JSONObject();
if (goodsId == 11) {
goods.put("笔记本", "5000");
} else {
goods.put("空调", "5000");
}
return goods;
}
@PostMapping(value="/common/fgadmin/login",consumes = "application/json;charset=utf-8")
public JSONObject postdemo2(@RequestBody JSONOject user,HttpServletResponse response) {
String username=user.getString("username");
String password=user.getString("password");
JSONObject result=new JSONObjectif(username.equals("admin")&&password.equals("123456")) {
result.put("msg", "ok");
}
SpringBoot是一个javaweb的开发框架,和SpringMVC类似,对比其他javaweb框架的好处,官方说是简化开发,约定大于配置, you can“just run",能迅速的开发web应用,几行代码开发一个http接口。