记一些零碎的总是忘记的问题-RestTemplate/Maven/Git/JDK升级

RestTemplate使用

POST请求

multipart/form-data 类型

假设body的参数为: params=xxx

public static Object getData() {
	// 假设请求地址为url
	String url = "https://www.baidu.com";
	// 创建请求头
	HttpHeaders headers = new HttpHeaders();
	// 设置请求内容类型为multipart/form-data
	headers.setContentType(MediaType.MULTIPART_FORM_DATA);
	// 设置请求体内容
	MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
	body.add("params", "xxx");
	// 创建请求实体
	HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body,headers);
	RestTemplate restTemplate = new RestTemplate();
	// 发送请求
	ResponseEntity<JsonNode> responseEntity = restTemplate.postForEntity(url, requestEntity, JsonNode.class);
	// 获取响应内容
	return responseEntity.getBody();
}

GET请求

参数拼接在url上,如https://www.baidu.com?searchWord=xxx&pageSize=10

public static Object getData() {
	String url = "https://www.baidu.com";
	// 设置url上的参数
	MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
	body.add("searchWord","xxx");
	body.add("pageSize","10");
	// 构建url
	UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
	// 参数放到url上
	URI newUri = builder.queryParams(body).build().encode().toUri();
	// 设置请求头
    HttpHeaders headers = new HttpHeaders();
    // 设置请求实体
    HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(headers);
    // 发送请求
	ResponseEntity<JsonNode> responseEntity = restTemplate.exchange(newUri, HttpMethod.GET, requestEntity, JsonNode.class);
	// 获取响应体
	return responseEntity.getBody();
}

maven依赖冲突

Mybatis-Plus

在这里插入图片描述

<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>2.0.6</version>
		</dependency>
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.5.6</version>
		</dependency>
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-extension</artifactId>
			<version>3.4.3</version>
			<exclusions>
				<exclusion>
					<artifactId>mybatis</artifactId>
					<groupId>org.mybatis</groupId>
				</exclusion>
				<exclusion>
					<artifactId>mybatis-spring</artifactId>
					<groupId>org.mybatis</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.4.3</version>
		</dependency>

依赖冲突导致LoggingFactory找不到

swagger报错

解决input String ""的问题

<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <exclusions>
    <exclusion>
     <groupId>io.swagger</groupId>
     <artifactId>swagger-models</artifactId>
    </exclusion>
   </exclusions>
   <version>2.9.2</version>
  </dependency>
  <dependency>
   <groupId>io.swagger</groupId>
   <artifactId>swagger-models</artifactId>
   <version>1.5.21</version>
  </dependency>

pagehelper分页失效

<dependency>
   <groupId>com.github.jsqlparser</groupId>
   <artifactId>jsqlparser</artifactId>
   <version>3.2</version>
  </dependency>
<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper-spring-boot-starter</artifactId>
   <version>1.3.0</version>
  </dependency>

Git 常用命令

一.推送当前项目到两个仓库

1.1 查看当前项目的远程仓库

git remote -v

origin https://enilu:mypassword@github.com/enilu/material-admin.git (fetch)

origin https://enilu:mypassword@github.com/enilu/material-admin.git (push)

1.2 添加远程仓库

git remote add zjg https://***/**.git

1.3 推送当前分支到指定仓库指定分支

git push zjg local-lyt:remote-lyt

二. 从tag中获取代码

git clone -b [tag] --depth=1 [git地址]
git branch [newbranch] [tag]
git checkout -b  [newbranch] [tag]git checkout [newbranch]

三. 带用户名密码拉取代码

@需要被转成%40, git地址中的http://需要去掉

git clone http://zhang:67%40j@gitlab.th.com/jc.git

四、Java17 信息收集

  1. 升级带来的问题:
  1. 各版本特性学习
  1. 推荐书籍
  1. 下载
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值