准备工作 页面downloadboostrap的官方实例页面,方便练习
资源来自:https://getbootstrap.com/docs/4.3/examples/
资源的目录如下:
1.controller层 package com.changyue.springbootresetfucrud.controller; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpSession; import java.util.Map; /** * @program: spring-boot-restful-crud * @description: 用户控制器 * @author: YuanChangYue * @create: 2019-08-13 17:59 */ @Controller public class LoginController { /** * 用户登录 * * @param username 用户名 默认测试 123 * @param password 密码 默认测试 123 * @param map map * @param httpSession session * @return 页面名称 */ @PostMapping("/user/login") public String login(@RequestParam("username") String username, @RequestParam("password") String password, Map<String, Object> map, HttpSession httpSession) { if ("123".
Spring Boot 与 Spring MVC 根据SpringBoot 官方文档中的资料 ,可以看出SpringBoot和SpringMVC的关系。
本章节提到的官文文档地址如下: <https://docs.spring.io/spring-boot/docs/2.1.7.RELEASE/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-auto-configuration
1. Spring Boot 中Spring MVC 自动配置 官方文档中的原文如下:
Spring Boot provides auto-configuration for Spring MVC that works well with most applications.
The auto-configuration adds the following features on top of Spring’s defaults:
Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
自动配置viewResolver (视图解析器:根据方法返回的值获得视图对象 ) ContentNegotiatingViewResolver : 组合所有的试图解析器 自定义:==可以自己给容器中添加视图解析器 ,自动为我们组合起来== Support for serving static resources, including support for WebJars (covered later in this document)).
Thymeleaf 模板引擎 1. 引入Thymeleaf <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> @ConfigurationProperties(prefix = "spring.thymeleaf") public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; 将html页面放在templates目录下使用模板引擎 渲染页面
html中引入
<html lang="en" xmlns:th="http://www.thymeleaf.org"> 2. 语法规则 来自官网的使用手册:http://www.thymeleaf.org
th 语法 表达式
Simple expressions:(表达式语法) Variable Expressions: ${...}:获取变量值;OGNL; 1)、获取对象的属性、调用方法 2)、使用内置的基本对象: #ctx : the context object. #vars: the context variables.
1. 开始使用 创建springBoot 应用 选择需要的模块 创建springboot
选择模块
SpringBoot 已经为我们把需要的配置自动装配好,只需要在后续的开发中,在配置文件中进行设置即可
编写代码
2. 自动配置 XXXXXAutoConfiguration :在容器中自动配置组件 XXXXXProperties : 配置类 这些文件都在通过Mavan引入的外部库中,org.springframework.boot.autoconfigure。
3. 静态资源映射规则 默认创建的 SpringBoot 项目是没有web文件夹的,那如何映射css,js等静态资源呢?
Spring boot 会自动装配WebMvcAutoConfiguration类,会对静态资源的映射做出规定,
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug("Default resource handling disabled"); return; } Duration cachePeriod = this.resourceProperties.getCache().getPeriod(); CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl(); if (!registry.hasMappingForPattern("/webjars/**")) { customizeResourceHandlerRegistration(registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/") .setCachePeriod(getSeconds(cachePeriod)).setCacheControl(cacheControl)); } String staticPathPattern = this.mvcProperties.getStaticPathPattern(); if (!
import java.util.Scanner; /** * @program: DSClassDesign * @description: 72:桶式排序 * @author: YuanChangYue * @TestData 6634 9796 435 1405 6123 10001 11459 12018 10372 19874 12860 11326 7096 30205 27010 * 6634,9796,435,1405,6123,10001,11459,12018,10372,19874,12860,11326,7096,30205,27010 * @create: 2019-06-18 11:49 */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] arrays = new int[15]; for (int i = 0; i < 15; i++) arrays[i] = in.nextInt(); in.close(); barrelSort(arrays); } /** * 进行桶排序 * * @param arr 排序的数组 */ private static void barrelSort(int[] arr) { int[][] bucket = new int[10][arr.