1. jar包和war包的介绍和区别

[TOC]

添加了数据库依赖,但没有配置,exclude 数据库

  • 选择依赖的时候如果加了数据库的依赖,启动的时候要配置好数据库,不然需要添加exclude = {DataSourceAutoConfiguration.class}

    • 选择以来加了Spring security 没有配置的话需要加

    • ```
      @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17

      # ClassPath

      **classpath 等价于 main/java + main/resources + 第三方jar包的根目录**。

      # ClassPath

      javaEE的项目,运行时将class文件加载到内存,

      ClassPath 就是存放class文件目录的绝对路径,

      可以通过类加载器获得ClassPath

      ```java
      ClassLoader classLoader = FirstServlet.class.getClassLoader();
      String path = classLoader.getResource("").getPath();
      System.out.println(path);

这里的path 就是ClassPath的路径

tomcat 打包以后 会将src/mian下面的.java 转化成.class文件加载到内存中

image-20210304220520767

image-20210304220541188

我们可以通过ClassPath获取 配置文件

Mevan 会将resources 目录的文件 放在和classpath同一目录下,

这样我们就可以获得配置资源文件了

Date 赋值时间

1
2
String dateString = "2018-02-23";
Date date= new SimpleDateFormat("yyyy-MM-dd").parse(dateString);

tkMapper查询

1
2
3
4
5
6
Example example=new Example(SpUser.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("username","zxh");
SpUser spUser = spUserMapper.selectOneByExample(example);
if(spUser.getPassword().equals("zxh228.."))
System.out.println("登录成功");

application.yml 模版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server:
port: 8989
servlet:
context-path: /shiro

spring:
datasource:
username: root
password: zxh228..
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/shiro
type: com.alibaba.druid.pool.DruidDataSource
application:
name: shiro
mvc:
view:
prefix: /
suffix: .jsp
mybatis:
mapper-locations: classpath:mapper/*.xml

JSON Date的格式化

1
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")

忽略返回值为null的 json

1
2
3
spring:
jackson:
default-property-inclusion: non_null

获取classPath

1
String filePath = ResourceUtils.getURL("classpath:").getPath()+"static/image/";