当前位置: 首页 > news >正文

鹤壁做网站哪家便宜山东今日热搜

鹤壁做网站哪家便宜,山东今日热搜,全国疫情最新名单,h5免费制作平台易企秀网页版一、创建及运行方式 1. 从官网导入: 注意:由于我的java版本是1.8;所以选中了spring2.7.14;如果你的java版本是9及以上,选中spring3相关的同时Java 版本也要对应起来 2. 创建第一个get请求 创建Controller package及…

一、创建及运行方式

1. 从官网导入:

注意:由于我的java版本是1.8;所以选中了spring2.7.14;如果你的java版本是9及以上,选中spring3相关的同时Java 版本也要对应起来

2. 创建第一个get请求

 创建Controller  package及类,创建以下的代码:

package com.example.aitestmini.controller;import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;//与前端请求的类
@RestController
public class firstController {//需求:get请求,路径/first, 前端显示hello springboot@GetMapping("/first")String first(){return "Hello Spring!";// http://localhost:8080/first}
}

运行:

运行AitestMiniApplication的run()方法

在浏览器访问http://localhost:8080/first,应该是展示hello spring

8080端口被占用,使用以下命令查看占用端口的pid:
lsof -i :8080
执行下面命令kill调进程:
kill -9 pid

3. 打包

mvn package 
执行以上命令,会在target/目录下自动生成jar包

4. 运行方式

方式一:
之前已经说过了,执行run()方法
方式二:
java -jar target/aitest-mini-0.0.1-SNAPSHOT.jar
运行以上命令,jar是刚才打出来的jar包
方式三:
mvn spring-boot:run
执行以上命令

二、端口管理

1. 常见端口实名方式

如果配置文件不声明端口,默认按照80801. application.properties配置文件管理端口:
server.port=80812. application.yml配置文件管理端口:
server:port: 80823. 运行命令声明端口
mvn clean package
java -jar -Dserver.port=8083 target/aitest-mini-0.0.1-SNAPSHOT.jar

2. 不同环境配置不同的端口

  • 针对环境创建不同的配置文件

 

 

 3. 运行不同环境端口的方式

1. application.properties管理:spring.profiles.active=dev2. application.yml管理
spring:profiles:active: dev3. 在pom文件管理<profiles><profile><id>dev</id><properties><profilesActive>dev</profilesActive></properties></profile><profile><id>qa</id><properties><profilesActive>qa</profilesActive></properties><!-- 默认qa环境--><activation><activeByDefault>true</activeByDefault></activation></profile></profiles>添加上面的依赖,在application.properties管理:
spring.profiles.active=@profilesActive@

三、Get请求Demo

1. 普通get请求的声明方式

1. 方法名前面使用:@GetMapping("/first")
2. 方法名前面使用:@RequestMapping(path = "/first",method = RequestMethod.GET)
@RestController
public class firstController {//需求:get请求,路径/first, 前端显示hello springboot
//    @GetMapping("/first")@RequestMapping(path = "/first",method = RequestMethod.GET)String first(){return "Hello Spring!";// http://localhost:8080/first}
}

2. 带有参数的Get请求

需求:
http://localhost:8081/topic/{id}
对应浏览器显示地址:{id}为内容
// 如果不想写@PathVariable("id")里面的id,需要保证传入的id->sid
@RestController
public class BaseGetWithIdController {@GetMapping("/topic/{id}")String getTopic(@PathVariable("id") String tid){return "请求的id为 " + tid + " 的内容!!!";}
}

3. 在queryParam拼接

需求:http://localhost:8081/native?s={sid}
对应浏览器显示地址:这是一个本国地址为:{sid}的内容
@GetMapping("/native")String getNative(@RequestParam("s") String sid){return "这是一个本国地址为:" + sid + " 的内容!";}

升级:

如果当s=66,打印不一样的内容:

@GetMapping("/native")String getNative(@RequestParam("s") String sid){return "这是一个本国地址为:" + sid + " 的内容!";}@GetMapping(path = "/native", params = {"s=66"})String getNative1(@RequestParam("s") String sid){return "这是一个本国地址为:" + sid + " 的内容!getNative1";}

4. 在controller前面加@RequestMapping("/t")

效果:相当于全部的链接前面加了/t会被自动识别

代码:

 @RequestMapping(path = "/first",method = RequestMethod.GET)String first(){return "Hello Spring!";// http://localhost:8080/first}

5. PathVariable参数非必填

//1. @PathVariable(value = "did",required = false)中的required默认是true,可以设置为false
//2. 声明完成之后, 对应的访问路径会有2中,需在GetMapping里面说明value = {"/topic/{did}/u","/topic/u"}@GetMapping(value = {"/topic/{did}/u","/topic/u"})String getTopic1(@PathVariable(value = "did",required = false) String topid,@RequestParam(defaultValue = "66") int sid){return "请求的id为 " + topid + " 的内容!!!并且参数sid为" + sid + "的内容!!!";}//http://localhost:8081/t/topic/99/u//http://localhost:8081/t/topic/u

6. RequestParam非必填及提供默认值

    @GetMapping("/top/{city}/{year}")String getRUIWithPara(@PathVariable int year,@PathVariable String city,@RequestParam(defaultValue = "GDP",required = false) String desc,@RequestParam(defaultValue = "45666") int money){return "{"+ year + "}年{" + city + "}人均{" + desc + "}为:{" + money + "}";}
1. desc非必填,但是GetMapping的值只有一个,因为desc的类型不是PathVariable
2. @RequestParam(defaultValue = "GDP",required = false) String desc说明RequestParam的required如果为false可以非必填

http://www.zhongyajixie.com/news/44553.html

相关文章:

  • 在线设计平台发展规划seo排名快速上升
  • wordpress 登录不上资源网站优化排名软件公司
  • 苹果钓鱼网站怎么做it培训四个月骗局
  • 中国最好的网站建设网站开发技术
  • 网站设计相似侵权吗免费的网站平台
  • 网站规划是什么意思江苏seo哪家好
  • 网站的图片怎么做显示和隐藏做免费推广的平台
  • 建设银行网站信息补充外贸平台自建站
  • 全网营销型推广网站建设网站域名购买
  • 潍坊快速网站排名百度广告联盟赚广告费
  • php做一个简单的动态网站网络优化公司哪家好
  • 网站方案策划书杭州网站外包
  • 寻找大连网站建设百度公司有哪些部门
  • 3d网站设计橘子seo
  • 自己做头像的网站百度账号注销
  • 敖降网站建设网络营销和电子商务的区别
  • wordpress ajax post厦门seo招聘
  • 交易所网站建设seo教程自学入门教材
  • wordpress商家目录云南网站建设快速优化
  • 网站怎么添加后台中国旺旺(00151) 股吧
  • c 开发web网站开发谈谈你对互联网营销的认识
  • 邢台网站建设平台网站品牌推广策略
  • b2b平台介绍南京seo网络优化公司
  • 做网站的公司有哪些广州网络推广选择
  • 大量网站开发视频 文档VIP资源广告公司名字
  • 做一个网站开发要多少钱百度搜索排名规则
  • 可以做网络攻防的实验的网站bt磁力在线种子搜索神器下载
  • 网站建公司网络营销策划书
  • 桓台网站制作网址大全百度
  • 张家界做网站的人口碑营销的优缺点