SpringBoot

报错

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-resources-plugin</artifactId>
   <version>2.4.3</version>
</plugin>

@SpringBootApplications : 标注这个类是一个springboot应用

1.Resources文件中

1.application.properties

#更改端口号
server.port=8080

2.application.yaml

#更改端口号
server:
  port: 8080
#访问路径:当前项目+static-path-pattern前缀+静态资源名=静态资源文件夹下找
spring:
  mvc:
  static-path-pattern: /res/**
#静态资源只有在/xxxx下访问
#源码"classpath:/META-INF/resources/","classpath:/resources/", "classpath:/static/", "classpath:/public/"
#也可以写成数组形式[classpath:/xxxx]
web:
  resources:
  static-locations: classpath:/xxxx 

3.可以创建一个banner.txt文件

里面可以写一些图案


//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//            佛祖保佑       永不宕机     永无BUG                    //

4.static/…见2

可以放图片,视频,js,css文件

2.例1,用yaml弄配置文件,注入值

     使用@ConfigurationProperties(prefix = "person")
     要导包,不导只是会爆红,可以正常运行,只是没有提示
     <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
     </dependency>
@Component
/*** 通过它,把yaml中数据和他绑定从而生效,弹幕中说这里面不能用驼峰命名,只能小写 ***/
@ConfigurationProperties(prefix = "person")
public class Person {
    private String name;
    private Integer age;
    private Boolean happy;
    private Date birth;
    private Map<String,Object> maps;
    private List<Object> list;
    private Dog dog;
    ..........
    }
Person:
  name: liu           yaml中可以写${}等等用法,如${random.int}随机产生一个int数
  age: 3
  happy: false
  birth: 2000/11/02
  maps: {k1: v1,k2: v2}
  list:
    - code
    - music
    - girl
  dog:
    name: 旺财          ${person.hello:hello}如果前面那个有值,就走前面的,没有就走后面的默认值
    age: 3

3.JSR303校验

需要导包

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

使用注解@Validated

@Pattern 可以使用正则表达式

4.thymeleaf

<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>

用于在temlates下写页面,需要以html结尾,源码得

而且该目录下,只能通过Controller来跳转访问

需要导入头部文件
<html xmlns:th="http://www.thymeleaf.org">
Simple expressions:
    Variable Expressions: ${...}
    Selection Variable Expressions: *{...}
    Message Expressions: #{...}
    Link URL Expressions: @{...}
    Fragment Expressions: ~{...}
Literals
    Text literals: 'one text', 'Another one!',…
    Number literals: 0, 34, 3.0, 12.3,…
    Boolean literals: true, false
    Null literal: null
    Literal tokens: one, sometext, main,…
Text operations:
    String concatenation: +
    Literal substitutions: |The name is ${name}|
Arithmetic operations:
    Binary operators: +, -, *, /, %
    Minus sign (unary operator): -
Boolean operations:
    Binary operators: and, or
    Boolean negation (unary operator): !, not
Comparisons and equality:
    Comparators: >, <, >=, <= (gt, lt, ge, le)
    Equality operators: ==, != (eq, ne)
Conditional operators:
    If-then: (if) ? (then)
    If-then-else: (if) ? (then) : (else)
    Default: (value) ?: (defaultvalue)
Special tokens:
    No-Operation: _

5.△!△!坑坑坑△!△!

后端接收数据要控制格式@RequestBody

上面是@RestController,后端接收数据要控制格式@RequestBody

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;
   @PostMapping("/sss")
    public Result save(@RequestBody User user){
       userService.saveUser(user);
       return Result.success();
   }

因为前后端分离了所以要加@RestController而不是Controller

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值