晋江做网站的公司哪家好,织梦怎么做淘客网站,个人网站推广方法,软文有哪几种类型一、SpringBoot介绍 由Pivotal团队提供的全新框架#xff0c;其设计目的是用来简化Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置#xff0c;从而使开发人员不再需要定义样板化的配置。SpringBoot提供了一种新的编程范式#xff0c;可以更加快速便捷…一、SpringBoot介绍 由Pivotal团队提供的全新框架其设计目的是用来简化Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置从而使开发人员不再需要定义样板化的配置。SpringBoot提供了一种新的编程范式可以更加快速便捷地开发Spring项目在开发过程当中可以专注于应用程序本身的功能开发而无需在Spring配置上花太大的工夫。
SpringBoot基于Spring4进行设计继承了原有Spring框架的优秀基因。SpringBoot准确的说并不是一个框架而是一些类库的集合。maven或者gradle项目导入相应依赖即可使用 SpringBoot而无需自行管理这些类库的版本。
二、SpringBoot特点
自动配置SpringBoot提供自动配置功能根据项目的依赖和环境自动设置 Spring应用程序减少了手动配置的复杂度。启动器SpringBoot提供“启动器”依赖集合如 spring-boot-starter-web 简化了项目的依赖管理。嵌入式服务器SpringBoot支持嵌入式服务器如Tomcat、Jetty和Undertow使得应用程序可以独立运行无需外部Web服务器。生产级别的特性SpringBoot具备生产级别的功能包括健康检查、应用监控、日志管理等。Actuator 模块可以轻松监控和管理应用程序。无配置的约定SpringBoot遵循“无配置”的原则使用合理的默认值和约定减少需要编写的配置代码。快速开发SpringBoot的项目结构和默认配置帮助开发者快速启动新项目。内置工具和插件支持开发、测试和部署。
三、Springboot3 版本要求 四、SpringBoot的项目结构 五、SpringBoot整合Web开发_静态资源 SpringBoot项目中没有WebApp目录只有src目录。在src/main/resources下面有static和templates两个文件夹。SpringBoot默认在static目录中存放静态资源而在templates中放动态页面。 index.html 页面
!DOCTYPE html
html langen
headmeta charsetUTF-8title测试/title!--脚本--script srcjs/index.js/script!--样式--link relstylesheet hrefcss/index.css/link
/head
bodydiv idapp!--图片--img srcimg/1.png altbutterfly/p/button onclickmy()单击我/button/div/body
/html
index.css
#app{background: lightcyan;height: 100vh;width: auto;display: flex;justify-content: center;align-items: center;
}button{width: 100px;height: 150px;
}
index.js
function my(){alert(测试JS);
}
运行 六、SpringBoot整合Web开发Servlet SpringBoot项目没有web.xml文件所以无法在web.xml中注册web组件SpringBoot有自己的方式注册web组件。
1、创建MyLoginServlet类
package com.hlx.springbootdemo1;import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;import java.io.IOException;
import java.io.PrintWriter;/*** author : HLX* ClassName :MyLoginServlet* date : 2024/11/19 15:34* Version :1.0* Description: TODO* modyified By :*/
WebServlet(/login)
public class MyLoginServlet extends HttpServlet {Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {// super.doGet(req, resp);//处理中文乱码问题resp.setContentType(text/html;charsetutf-8);//获取输出流PrintWriter out resp.getWriter();//页面输出out.println(登录成功欢迎你br /br /);out.println(Welcome,Login Successfully!);//控制台输出System.out.println(登录成功);//刷新缓冲区关闭输出流out.flush();out.close();}Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {super.doPost(req, resp);}
}2、启动类扫描web组件
package com.hlx.springbootdemo1;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;// SpringBootApplication
SpringBootApplication(exclude {DataSourceAutoConfiguration.class})
//SpringBoot启动时扫描注册注解标注的Web组件
ServletComponentScan
public class SpringbootDemo1Application {public static void main(String[] args) {SpringApplication.run(SpringbootDemo1Application.class, args);}}3、index.html页面 4、运行