周浦做网站,美管加登录平台,品牌网上和实体店质量一样吗,网站备案期间做网页基本概念
春天
Spring 是用于开发 Java 应用程序的开源框架#xff0c;为解决企业应用开发的复杂性而创建。
Spring 的基本设计思想是利用 IOC#xff08;依赖注入#xff09;和 AOP #xff08;面向切面#xff09;解耦应用组件#xff0c;降低应用程序各组件之间的耦…基本概念
春天
Spring 是用于开发 Java 应用程序的开源框架为解决企业应用开发的复杂性而创建。
Spring 的基本设计思想是利用 IOC依赖注入和 AOP 面向切面解耦应用组件降低应用程序各组件之间的耦合度。在这两者的基础上Spring 逐渐衍生出了其他的高级功能如 SecurityJPA 等。
Spring MVC
Spring MVC 是 Spring 的子功能模块专用于 Web 开发。
Spring MVC 基于 Servlet 实现将 Web 应用中的数据业务、显示逻辑和控制逻辑进行分层设计。开发者可以直接调用 Spring MVC 框架中 Spring 解耦的组件快速构建 Web 应用。
Spring 引导
Spring Boot 是用于简化创建 Spring 项目配置流程快速构建 Spring 应用程序的辅助工具。Spring Boot 本身并不提供 Spring 框架的核心特性以及扩展功能。但 在创建 Spring 项目时Spring Boot 可以
自动添加 Maven 依赖不需要在 pom.xml 中手动添加配置依赖。不需要配置 XML 文件将全部配置浓缩在一个 appliaction.yml 配置文件中。自动创建启动类代表着本工程项目和服务器的启动加载。内嵌 Tomcat 、Jetty 等容器无需手动部署 war 文件。 Spring Boot 配置
依赖
在Spring Boot中引入的所有包都是 starter 形式
spring-boot-starter-web-services针对 SOAP Web Services spring-boot-starter-web针对 Web 应用与网络接口 spring-boot-starter-jdbc针对 JDBC spring-boot-starter-data-jpa基于 Hibernate 的持久层框架 spring-boot-starter-cache针对缓存支持
默认映射路径 classpath:/META-INF/resources/classpath:/resources/classpath:/static/classpath:/public/ 优先级顺序META-INF/resources 资源 static public
全局配置
位于 resources 文件夹下支持以下两种格式。由 Spring Boot 自动加载。
application.propertiesapplication.yml
#端口号
server.port8080
#访问前缀
server.servlet.context-path/demo#端口号
server.port8080
#访问前缀
server.servlet.context-path/demo#数据库驱动
jdbc.drivercom.mysql.jc.jdbc.Driver
#数据库链接
jdbc.urljdbc:mysql://localhost:3306/demo?useUnicodetruecharacterEncodingutf8useSSLfalseserverTimezoneUTC
#数据库用户名
jdbc.usernameroot
#数据库密码
jdbc.passwordwdh19970506#Mybatis
#配置文件路径
mybatis_config_filemybatis-config.xml
#SQL语句配置路径
mapper_path/mapper/**.xml
#实体类所在包
type_alias_packagecom.example.demo.entity JDBC 连接 Mysql5 驱动 com.mysql.jdbc.DriverJDBC 连接 Mysql6 驱动 com.mysql.cj.jdbc.Driver URL 必须要指定时区 serverTimezone
多重配置
在 Spring Boot 中我们往往需要配置多个不同的配置文件去适应不同的环境
application-dev.properties开发环境application-test.properties测试环境application-prod.properties生产环境
只需要在程序默认配置文件 中设置环境就可以使用指定的配置。application.properties
spring.profiles.activedev
启动类
SpringBootApplication类作为程序入口在创建 Spring Boot 项目时自动创建。
等同于 会自动完成配置并扫描路径下所有包。ConfigurationEnableAutoConfigurationComponentScan
SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}} Spring 需要定义调度程序 servlet 映射和其他支持配置。我们可以使用 web.xml 文件或 Initializer 类来完成此操作
public class MyWebAppInitializer implements WebApplicationInitializer {Overridepublic void onStartup(ServletContext container) {AnnotationConfigWebApplicationContext context new AnnotationConfigWebApplicationContext();context.setConfigLocation(com.pingfangushi);container.addListener(new ContextLoaderListener(context));ServletRegistration.Dynamic dispatcher container.addServlet(dispatcher, new DispatcherServlet(context));dispatcher.setLoadOnStartup(1);dispatcher.addMapping(/);}
} 还需要将 注释添加到 类并定义一个视图解析器来解析从控制器返回的视图EnableWebMvcConfiguration
EnableWebMvc
Configuration
public class ClientWebConfig implements WebMvcConfigurer { Beanpublic ViewResolver viewResolver() {InternalResourceViewResolver bean new InternalResourceViewResolver();bean.setViewClass(JstlView.class);bean.setPrefix(/WEB-INF/view/);bean.setSuffix(.jsp);return bean;}
}