移位符
- “<<” 代表 乘2
- ” >>" 代表 除以2
Integer a = 8;
Integer b = a << 3; // *2的三次方 = a*8
Integer c = a >> 3; // /2的三次方 = a/8
System.out.println(b); // 64
System.out.println(c); // 1
操作统一返回类
package com.xxx.common.support.controller;
import com.xxx.common.constant.GlobalConstant;
import com.xxx.common.support.domain.IEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* ApiResponse
* Description: 操作统一返回
* Author: xxx
* Date: 2022-01-13
**/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ApiResponse implements IEntity {
/**
* @Fields serialVersionUID : 序列化标识
*/
private static final long serialVersionUID = GlobalConstant.SERIAL_VERSION_UID;
/**
* 成功码
*/
public static final String SUCCESS_CODE = "SUCCESS";
/**
* 成功信息
*/
public static final String SUCCESS_MESSAGE = "操作成功";
/**
* 错误码
*/
public static final String ERROR_CODE = "FAIL";
/**
* 错误信息
*/
public static final String ERROR_MESSAGE = "操作失败";
/** 状态码 */
private String retcode;
/** 返回内容 */
private String retmsg;
/** 数据对象 */
private Object data;
/**
* 返回成功消息
*
* @return 成功消息
*/
public static ApiResponse success() {
return ApiResponse.successMsg(SUCCESS_MESSAGE);
}
/**
* 返回成功消息
*
* @return 成功消息
*/
public static ApiResponse successMsg(String msg) {
return ApiResponse.success(msg, null);
}
/**
* 返回成功数据
*
* @return 成功消息
*/
public static ApiResponse success(Object data) {
return ApiResponse.success(SUCCESS_MESSAGE, data);
}
/**
* 返回成功消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 成功消息
*/
public static ApiResponse success(String msg, Object data) {
return new ApiResponse(SUCCESS_CODE, msg, data);
}
/**
* 返回错误消息
*
* @return 错误消息
*/
public static ApiResponse error() {
return ApiResponse.error(ERROR_MESSAGE, null);
}
/**
* 返回错误消息
*
* @return 错误消息
*/
public static ApiResponse errorMsg(String msg) {
return ApiResponse.error(msg, null);
}
/**
* 返回错误数据
*
* @return 错误消息
*/
public static ApiResponse error(Object data) {
return ApiResponse.error(ERROR_MESSAGE, data);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 错误消息
*/
public static ApiResponse error(String msg, Object data) {
return new ApiResponse(ERROR_CODE, msg, data);
}
/***
*
* success
* Description: 返回自定义编码和返回值
* Author: xxx
* @Date: 2022-01-13
**/
public static ApiResponse success(String code, String msg, Object data) {
return new ApiResponse(code, msg, data);
}
/***
*
* @Title:: error
* @Description: 返回自定义编码和返回值
* @Author: xxx
* @Date: 2022-01-13
**/
public static ApiResponse error(String code, String msg, Object data) {
return new ApiResponse(code, msg, data);
}
}
spring boot升级到jdk11出现错误
Spring Boot 警告:An illegal reflective access operation has occurred
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/D:/Android/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.0.RELEASE/e0e1b3c304f70ed19d7905975f6f990916ada219/spring-core-5.2.0.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
解决方式:增加 JVM 启动参数 java --illegal-access=deny(不知道为什么测试时候没生效)
不推荐方式: jdk版本降到1.8
SpringBoot项目使用MySQL数据库,误用数据库关键字
JPA
//实体类加此注解
@Column(name = "medicine_name")
private String medicineName;
Mybatis-plus
//实体类加此注解
@TableField(value = "`describe`")
private String describe;
String类型api接口返回值不加双引号
import javax.servlet.http.HttpServletResponse;
...
public void result(String string, HttpServletResponse response) throws Exception {
response.getWriter().write(string);
response.getWriter().flush();
response.getWriter().close();
}
Java8 stream流使用
//筛选状态为2和3的数据
List<CardDto> resultCardList = cardDtos.stream().filter(s -> ("2".equals(s.getStatus()) || "3".equals(s.getStatus()))).collect(Collectors.toList());
//筛选状态为1的数据
List<CardDto> pendingCardList = cardDtos.stream().filter(s -> "1".equals(s.getStatus())).collect(Collectors.toList());
//获取list对象中的configId属性集合
List<Long> configIds = pendingCardList.stream().map(CardDto::getConfigId).collect(Collectors.toList());
//合起来写 (筛选状态为1的数据的configId集合)
List<Long> ids = cardDtos.stream().filter(s -> "1".equals(s.getStatus())).collect(Collectors.toList()).stream().map(CardDto::getConfigId).collect(Collectors.toList());
//分组 Stream的Collectors.groupingBy支持key为null进行分组
//此时这里会抛出空指针异常
Map<String, List<User>> userMap = userList.stream.collect(Collectors.groupingBy(x -> x.getSex()));
//使用Optional包装一层(解决空指针异常)
Map<Optional<String>, List<User>> userMap = userList.stream().collect(Collectors.groupingBy(x -> Optional.ofNullable(x.getSex())));
}
mybatis 中xml 里判断list写法
<update id="updateStatus">
UPDATE xx表
SET `status` = "3"
WHERE
del_flag = "0"
<if test="ids != null and ids.size()!=0">
AND id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
</update>
springboot项目,@Async异步方法需自己解决循环依赖问题,但是不使用异步方法spring boot会内部解决,不会抛出异常
springboot组件修改Pageable 值
Pageable pageable = PageRequest.of(0, Integer.parseInt(size), pageable.getSort());
//or
pageable= PageRequest.of(page,pageSize, Sort.by(Sort.Direction.DESC,"time"));
项目部署
springboot 项目打包:
mvn clear package
重启服务:
systemctl restart xxxService
vue 项目:
npm run build:prod (打包好的文件在dist文件夹需替换4个)
(打包后部署到dash…)