一、Spring Boot的创建
1.Spring Boot简化Spring程序的开发,使用注解和配置的方式开发


springboot内置了tomact服务器
tomact:web服务器,默认端口号8080,所以访问程序使用8080

src/main/java:Java源代码
src/main/resource:静态资源或配置文件,存放前端代码(js,css,html)
src/test/java:测试代码源代码
target:编译后的文件路径
pom.xml:maven配置文件

浏览器输入网址
通过ip地址127.0.0.1定位网络上的一台计算机(本机)
通过端口号找到计算机上对应的进程,本机正在运行的8080端口的程序
/helle 请求资源(数据)的位置
服务器
接受浏览器发送的信息,在服务器上找到相应的资源(数据)

404:访问的资源不存在(url错误,注解错误)
500:服务器内部错误(程序错误)
无法访问此网站:可能Tomcat启动失败,服务未成功启动,ip/端口写错
二、Spring Web MVC
1.MVC(Model View Controller)
是软件工程中的一种软件架构设计模式,把软件系统分为模型,视图,,控制器三个部分
View:与浏览器进行交互,展示数据的资源
Mode:应用程序的主体部分,处理业务逻辑处理数据
Controller:分发器,用来连接视图和模型
SpringMVC是一个Web框架,是对MVC思想的具体实现
SpringBoot只是实现SpringMVC的其中一种方式,通过2,添加SpringWeb来实现web功能
2.如何通过浏览器和用户程序进行交互
1)建立连接
用户(浏览器)和JAVA程序连接起来,(访问一个地址,能够调用Spring程序)
常使用的注解
@RequestMapping
实现URL路由映射,浏览器连接程序
当用户访问⼀个 URL 时, 将用户的请求对应到程序中某个类的某个方法的过程就叫路由映射
可以修饰类也可以修饰方法,访问地址:...类路径+方法路径
即支持Get请求,也支持Post请求
可以显示指定接收Post请求


2)请求:
用户请求时会带一些参数,在程序中要实现获取参数的功能
如何传递参数到后端以及后端如何接收
1)传递单个/多个参数

使用浏览器发送请求并传参
springMVC会根据方法发的参数名,找到对应的参数,赋值给方法
url中?后name对程序应方法中的参数name必须一致
参数可能为空的数据,使用包装类型(Integer..)

传递多个参数,就是程序中方法有多个形参,请后端参数进行匹配时,通过参数名进行匹配
2)传递对象
参数较多时,可以把这些参数封装成一个对象



使用postman测试接口

3)参数重命名
保证前后端对应参数能匹配上
@RequestParam
url路径应该写参数nowtime现在可以使用time


使用注解@RequestParam请求参数必须和注解声明的名称一致,而且参数成为必传参数feibichuan
可以修改为参数为非必传参数

4)传递数组
MVC可自动绑定数组参数的赋值



5)传递集合
集合`参数和数组类似 ,默认情况下请求中参数名相同的多个值封装到数组,要使用@RequestParam绑定参数关系

6)传递JSON数据
JSON:JavaScript对象表示法,一种数据格式,使用文本表示一个对象的信息,使用键值对表示数据
@RequestBody注解.请求正文


3)响应:
执行业务逻辑后,把执行结果返回给用户
,