目录
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 信息收集
- 升级带来的问题:
- 各版本特性学习
- 推荐书籍
- 下载