hello,大家早,新的一周开始了,我们今天简单聊一聊web开发,“web开发”这个耳熟能详的词,是涉及前端+后端的一个系统工程,前端作为一个系统的门面,负责长的好看、酷炫、用户交互的友好性;而后端则负责对于用户请求的处理、过滤以及数据的存储等,以大家常用的的淘宝为例:
在主页🔍 “运动鞋” ,然后点击搜索,就会将搜索的请求传到后端,触发后端功能:
接下来给大家分享下用SpringBoot来开发一个最简单的后端demo,SpringBoot作为当今最流行的Java Web开发框架之一,已经成为大多数公司的必备之选。
- 第一步:通过Spring官网的工具(https://start.spring.io/)来自动生成一个demo工程;
- 第二步:增加代码
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @GetMapping("/hello") public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { return String.format("Hello %s!", name); } }
- 第三步:启动
MacOS/Linux:
./mvnw spring-boot:run
Windows:
mvnw spring-boot:run
- 第四步:访问本地网站
http://localhost:8080/hello
一个最简单的web网站就已经建好了,阅读千百遍不如实际做一遍,来试试吧。
声明:来自ven coding,仅代表创作者观点。链接:https://eyangzhen.com/8497.html