11-web实战-新增员工

1. 新增员工

主表明细表

 @Options(useGeneratedKeys = true, keyProperty = "id")   //获取主键的值并赋给id属性
<insert id="insert" useGeneratedKeys="true" keyProperty="id">

2. 事务管理

事务和传播

@Transational(rollbackfor=Exception.class, Propagation=Transation.REQUIRED)

//Transation.REQUIRED
//Transation.REQUIRE_NEW

A->事务方法B
//B上注解的值:
//Transation.REQUIRED 如果A有事务,加入。没有,自己创建事务。
//Transation.REQUIRE_NEW 不管A,自己创建新的事务

yml配置

#打开spring事务管理的debug日志  
logging:  
  level:  
    org:  
      springframework:  
        jdbc:  
          support:  
            JdbcTransactionManager: debug
   

3. 上传文件

3.1. springboot 本地上传,和注意事项

表单要求:

后端代码

@PostMapping("/upload")
public Result upload(MultipartFile file) {
    String file = file.getOriginalName();
    String suffix = file.substract(file.lastIndexOf("."));
    String name = UUID.randomUuid() + suffix;
    file.transferTo(new File("D:/images/"+name));
}

配置

//spring:下
servlet:  
  multipart:  
    #单个文件最大可上传的大小,默认时1MB  
    max-file-size: 10MB  
    #单次请求所有文件最大可上传的大小,默认时10MB  
    max-request-size: 100MB

3.2. 阿里云 OSS

Cite

准备:

注解:

//获取单个属性
@Value("${oss.key}")
private String key;


@Data
@Component
@ConfigurationProperites(prefix="oss")
//配置类 获取yml得多个属性


#自定义配置  
aliyun:  
  oss:  
    endpoint: https://oss-cn-shenzhen.aliyuncs.com  
    bucket: xxxx

4. 配置文件

yml 注意事项:

# app 表示的对象(map) key-value键值对
app:
  name: jack
  version: 1
  # users表示的 数组/集合
  users:
    - jack # 作者1
    - tom # 作者2
    - john # 作者3

上一节:10-web实战-多表操作-员工列表查询

下一节:12-web实战-删除-修改