---恢复内容开始---

====================2、SpringBoot接口Http协议开发实战 =============================

1、SpringBoot2.xHTTP请求配置讲解

简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧

1、@RestController and @RequestMapping是springMVC的注解,不是springboot特有的
2、@RestController = @Controller+@ResponseBody

@ResponseBody 返回的数据是json
3、@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan
localhost:8080

2、开发接口必备工具之PostMan接口调试工具介绍和使用
简介:模拟Http接口测试工具PostMan安装和讲解

1、接口调试工具安装和基本使用
2、下载地址:https://www.getpostman.com/

3、SpringBoot基础HTTP接口GET请求实战
简介:讲解springboot接口,http的get请求,各个注解使用
1、GET请求
1、单一参数@RequestMapping(path = "/{id}", method = RequestMethod.GET)
1) public String getUser(@PathVariable String id ) {}

2)@RequestMapping(path = "/{depid}/{userid}", method = RequestMethod.GET) 可以同时指定多个提交方法
getUser(@PathVariable("depid") String departmentID,@PathVariable("userid") String userid)

3)一个顶俩
@GetMapping = @RequestMapping(method = RequestMethod.GET)
@PostMapping = @RequestMapping(method = RequestMethod.POST)
@PutMapping = @RequestMapping(method = RequestMethod.PUT)
@DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)

4)@RequestParam(value = "name", required = true)
可以设置默认值,比如分页

4)@RequestBody 请求体映射实体类
需要指定http头为 content-type为application/json charset=utf-8

5)@RequestHeader 请求头,比如鉴权
@RequestHeader("access_token") String accessToken

6)HttpServletRequest request自动注入获取参数

4、SpringBoot基础HTTP接口POST,PUT,DELETE请求实战
简介:讲解http请求post,put, delete提交方式

5、常用json框架介绍和Jackson返回结果处理
简介:介绍常用json框架和注解的使用,自定义返回json结构和格式

1、常用框架 阿里 fastjson,谷歌gson等
JavaBean序列化为Json,性能:Jackson > FastJson > Gson > Json-lib 同个结构
Jackson、FastJson、Gson类库各有优点,各有自己的专长
空间换时间,时间换空间

2、jackson处理相关自动
指定字段不返回:@JsonIgnore
指定日期格式:@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",locale="zh",timezone="GMT+8")
空字段不返回:@JsonInclude(Include.NON_NUll)
指定别名:@JsonProperty

6、SpringBoot2.x目录文件结构讲解
简介:讲解SpringBoot目录文件结构和官方推荐的目录规范

1、目录讲解
src/main/java:存放代码
src/main/resources
static: 存放静态文件,比如 css、js、image, (访问方式 http://localhost:8080/js/main.js)
templates:存放静态页面jsp,html,tpl
config:存放配置文件,application.properties
resources:

2、引入依赖 Thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
注意:如果不引人这个依赖包,html文件应该放在默认加载文件夹里面,
比如resources、static、public这个几个文件夹,才可以访问

3、同个文件的加载顺序,静态资源文件
Spring Boot 默认会挨个从
META/resources > resources > static > public 里面找是否存在相应的资源,如果有则直接返回。

4、默认配置
1)官网地址:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content

2)spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

5、静态资源文件存储在CDN

7、SpringBoot2.x文件上传实战
简介:讲解HTML页面文件上传和后端处理实战
1、讲解springboot文件上传 MultipartFile file,源自SpringMVC

1)静态页面直接访问:localhost:8080/index.html
注意点:
如果想要直接访问html页面,则需要把html放在springboot默认加载的文件夹下面
2)MultipartFile 对象的transferTo方法,用于文件保存(效率和操作比原先用FileOutStream方便和高效)

访问路径 http://localhost:8080/images/39020dbb-9253-41b9-8ff9-403309ff3f19.jpeg

package net.xdclass.demo.domain;

import java.io.Serializable;

public class JsonData implements Serializable {
private static final long serialVersionUID = 1L; //状态码,0表示成功,-1表示失败
private int code; //结果
private Object data; //错误描述
private String msg; public int getCode() {
return code;
} public String getMsg() {
return msg;
} public void setMsg(String msg) {
this.msg = msg;
} public void setCode(int code) {
this.code = code;
} public Object getData() {
return data;
} public void setData(Object data) {
this.data = data;
} public JsonData(int code, Object data) {
super();
this.code = code;
this.data = data;
} public JsonData(int code, String msg,Object data) {
super();
this.code = code;
this.msg = msg;
this.data = data;
} }

jsondata

package net.xdclass.demo.controller;

import java.io.File;
import java.io.IOException;
import java.util.UUID; import javax.servlet.http.HttpServletRequest; import net.xdclass.demo.domain.JsonData; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; /**
* 功能描述:文件测试
*
* <p> 创建时间:Apr 22, 2018 11:22:29 PM </p>
* <p> 作者:小D课堂</p>
*/
@Controller
public class FileController { @RequestMapping(value = "/api/v1/gopage")
public Object index() { return "index";
} private static final String filePath = "/Users/jack/Desktop/person/springboot/xdclass_springboot/src/main/resources/static/images/"; @RequestMapping(value = "upload")
@ResponseBody
public JsonData upload(@RequestParam("head_img") MultipartFile file,HttpServletRequest request) { //file.isEmpty(); 判断图片是否为空
//file.getSize(); 图片大小进行判断 String name = request.getParameter("name");
System.out.println("用户名:"+name); // 获取文件名
String fileName = file.getOriginalFilename();
System.out.println("上传的文件名为:" + fileName); // 获取文件的后缀名,比如图片的jpeg,png
String suffixName = fileName.substring(fileName.lastIndexOf("."));
System.out.println("上传的后缀名为:" + suffixName); // 文件上传后的路径
fileName = UUID.randomUUID() + suffixName;
System.out.println("转换后的名称:"+fileName); File dest = new File(filePath + fileName); try {
file.transferTo(dest); return new JsonData(0, fileName);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return new JsonData(-1, "fail to save ", null);
} }

FileController

8、jar包方式运行web项目的文件上传和访问处理(核心知识)
简介:讲解SpingBoot2.x使用 java -jar运行方式的图片上传和访问处理

1、文件大小配置,启动类里面配置

@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("10240KB"); //KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("1024000KB");
return factory.createMultipartConfig();
}

2、打包成jar包,需要增加maven依赖
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
如果没加相关依赖,执行maven打包,运行后会报错:no main manifest attribute, in XXX.jar

GUI:反编译工具,作用就是用于把class文件转换成java文件

3、文件上传和访问需要指定磁盘路径
application.properties中增加下面配置
1) web.images-path=/Users/jack/Desktop
2) spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/test/,file:${web.upload-path}

web.images-path=/Users/jack/Desktop  加入到路径中来,可以直接

4、文件服务器:fastdfs,阿里云oss,nginx搭建一个简单的文件服务器

---恢复内容结束---

====================2、SpringBoot接口Http协议开发实战 =============================

1、SpringBoot2.xHTTP请求配置讲解

简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧

1、@RestController and @RequestMapping是springMVC的注解,不是springboot特有的
2、@RestController = @Controller+@ResponseBody

@ResponseBody 返回的数据是json
3、@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan
localhost:8080

2、开发接口必备工具之PostMan接口调试工具介绍和使用
简介:模拟Http接口测试工具PostMan安装和讲解

1、接口调试工具安装和基本使用
2、下载地址:https://www.getpostman.com/

3、SpringBoot基础HTTP接口GET请求实战
简介:讲解springboot接口,http的get请求,各个注解使用
1、GET请求
1、单一参数@RequestMapping(path = "/{id}", method = RequestMethod.GET)
1) public String getUser(@PathVariable String id ) {}

2)@RequestMapping(path = "/{depid}/{userid}", method = RequestMethod.GET) 可以同时指定多个提交方法
getUser(@PathVariable("depid") String departmentID,@PathVariable("userid") String userid)

3)一个顶俩
@GetMapping = @RequestMapping(method = RequestMethod.GET)
@PostMapping = @RequestMapping(method = RequestMethod.POST)
@PutMapping = @RequestMapping(method = RequestMethod.PUT)
@DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)

4)@RequestParam(value = "name", required = true)
可以设置默认值,比如分页

4)@RequestBody 请求体映射实体类
需要指定http头为 content-type为application/json charset=utf-8

5)@RequestHeader 请求头,比如鉴权
@RequestHeader("access_token") String accessToken

6)HttpServletRequest request自动注入获取参数

4、SpringBoot基础HTTP接口POST,PUT,DELETE请求实战
简介:讲解http请求post,put, delete提交方式

5、常用json框架介绍和Jackson返回结果处理
简介:介绍常用json框架和注解的使用,自定义返回json结构和格式

1、常用框架 阿里 fastjson,谷歌gson等
JavaBean序列化为Json,性能:Jackson > FastJson > Gson > Json-lib 同个结构
Jackson、FastJson、Gson类库各有优点,各有自己的专长
空间换时间,时间换空间

2、jackson处理相关自动
指定字段不返回:@JsonIgnore
指定日期格式:@JsonFormat(pattern="yyyy-MM-dd hh:mm:ss",locale="zh",timezone="GMT+8")
空字段不返回:@JsonInclude(Include.NON_NUll)
指定别名:@JsonProperty

6、SpringBoot2.x目录文件结构讲解
简介:讲解SpringBoot目录文件结构和官方推荐的目录规范

1、目录讲解

src/main/java:存放代码
src/main/resources
static: 存放静态文件,比如 css、js、image, (访问方式 http://localhost:8080/js/main.js)
templates:存放静态页面jsp,html,tpl
config:存放配置文件,application.properties
resources:

2、引入依赖 Thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
注意:如果不引人这个依赖包,html文件应该放在默认加载文件夹里面,
比如resources、static、public这个几个文件夹,才可以访问

3、同个文件的加载顺序,静态资源文件
Spring Boot 默认会挨个从
META/resources > resources > static > public 里面找是否存在相应的资源,如果有则直接返回。

4、默认配置
1)官网地址:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content

2)spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/

5、静态资源文件存储在CDN

7、SpringBoot2.x文件上传实战
简介:讲解HTML页面文件上传和后端处理实战
1、讲解springboot文件上传 MultipartFile file,源自SpringMVC

1)静态页面直接访问:localhost:8080/index.html
注意点:
如果想要直接访问html页面,则需要把html放在springboot默认加载的文件夹下面
2)MultipartFile 对象的transferTo方法,用于文件保存(效率和操作比原先用FileOutStream方便和高效)

访问路径 http://localhost:8080/images/39020dbb-9253-41b9-8ff9-403309ff3f19.jpeg

8、jar包方式运行web项目的文件上传和访问处理(核心知识)
简介:讲解SpingBoot2.x使用 java -jar运行方式的图片上传和访问处理

1、文件大小配置,启动类里面配置

@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("10240KB"); //KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("1024000KB");
return factory.createMultipartConfig();
}

2、打包成jar包,需要增加maven依赖
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
如果没加相关依赖,执行maven打包,运行后会报错:no main manifest attribute, in XXX.jar

GUI:反编译工具,作用就是用于把class文件转换成java文件

3、文件上传和访问需要指定磁盘路径
application.properties中增加下面配置
1) web.images-path=/Users/jack/Desktop
2) spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/test/,file:${web.upload-path}

4、文件服务器:fastdfs,阿里云oss,nginx搭建一个简单的文件服务器

小D课堂【SpringBoot】接口Http协议开发实战的更多相关文章

  1. 2、SpringBoot接口Http协议开发实战8节课(1-6)

    1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...

  2. 小D课堂 - 零基础入门SpringBoot2.X到实战_第2节 SpringBoot接口Http协议开发实战_6、SpringBoot2.xHTTP请求配置讲解

    1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...

  3. 2、SpringBoot接口Http协议开发实战8节课(7-8)

    7.SpringBoot2.x文件上传实战 简介:讲解HTML页面文件上传和后端处理实战 1.讲解springboot文件上传 MultipartFile file,源自SpringMVC 1)静态页 ...

  4. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-1.SpringBoot整合微信支付开发在线教育视频站点介绍

    笔记 第一章项目介绍和前期准备 1.SpringBoot整合微信支付开发在线教育视频站点介绍     简介: 课程介绍,和小D课堂在线教育项目搭建开发 1.课程大纲介绍         2.微信支付项 ...

  5. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_汇总

    2018年Spring Boot 2.x整合微信支付在线教育网站高级项目实战视频课程 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-1.SpringBoot整合微信支付开发在 ...

  6. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-10.Springboot2.x用户登录拦截器开发实战

    笔记 10.Springboot2.x用户登录拦截器开发实战     简介:实战开发用户登录拦截器拦截器 LoginInterceptor                  1.实现接口 LoginI ...

  7. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-1.数据信息安全--微信授权一键登录功能介绍

    笔记 1.数据信息安全--微信授权一键登录功能介绍 简介:讲解登录方式优缺点和微信授权一键登录功能介绍         1.手机号或者邮箱注册             优点:              ...

  8. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-3.Vidoe相关接口完善和规范协议

    笔记 3 .Vidoe相关接口完善和规范协议     简介:完善相关接口,协议规范讲解 1.save接口保存对象             1)@RequestParam(value = "p ...

  9. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-8.用户模块开发之保存微信用户信息

    笔记 8.用户模块开发之保存微信用户信息     简介:开发User数据访问层,保存微信用户信息 问题:             微信回调 用户昵称乱码             解决:        ...

随机推荐

  1. day040 数据库索引补充 存储过程 事务等

    1.正确使用索引 视图: 关键词 view 视图是体格虚拟表 创建视图 : create view 视图名称 as sql语句; 例: create view t_view as select * f ...

  2. 主机访问虚拟机centos7的服务器

    一.虚拟机开启桥梁接 1.编辑-->虚拟网络编辑器 2.虚拟机-->设置 二.Centos的配置---关闭防火墙下的服务器接口 Centos7.0 默认使用firewall作为防火墙,这里 ...

  3. (C/C++学习笔记) 二十四. 知识补充

    二十四. 知识补充 ● 子类调用父类构造函数 ※ 为什么子类要调用父类的构造函数? 因为子类继承父类,会继承到父类中的数据,所以子类在进行对象初始化时,先调用父类的构造函数,这就是子类的实例化过程. ...

  4. GD2模块-图像处理

    GD2模块-图像处理 1.图像处理模块的主要功能: a) 验证码 b) 加盖水印 c) 缩略图 d) 帖子图片签名 e) 在线LOGO制作 2确认PHP是否支持图像处理 检测PHPINFO文件中是否存 ...

  5. Chrome浏览器录屏扩展插件

    Chrome浏览器录屏扩展插件,可以录制网页操作或者桌面操作.生成MP4 Loom https://chrome.google.com/webstore/detail/loom-video-recor ...

  6. loader 的理解

    [ webpack3.0.0刚刚出来  所以文章是跟着低版本 教程 操作熟悉  结果好多对不上喔] 四:理解less-loader加载器的使用 我们先来理解下less-loader加载器,其他的sas ...

  7. iframe 常见问题 解析

    1. jquery在iframe子页面获取父页面元素代码如下: $("#objid",parent.document) 2. jquery在父页面获取iframe子页面的元素代码如 ...

  8. Python 基础day3

    1.简述bit,byte,kb,MB,GB,TB的关系 1TB=1024GB;   1GB=1024MB ;  1MB=1024kb: 1kb=1024byte ; 1byte=8bit 2.简述as ...

  9. jQuery中extend()实现原理

    jQuery.extend使用的几种方式 1.jQuery.extend(源对象) jQuery源代码: if(length == i){ target = this; --i; } 示例1: var ...

  10. NAVICAT for 32位/64位 及破解工具PatchNavicat

    Navicat提供多达 7 种语言供客户选择,被公认为全球最受欢迎的数据库前端用户介面工具. 它可以用来对本机或远程的 MySQL.SQL Server.SQLite.Oracle 及 Postgre ...