Summary

1.增加/删除/修改是否成功或则失败,添加事务。
Post/Delete/Put,实现类的方法上面加以下注解即可。

@Transactional(rollbackFor = Exception.class)

2.根据id去查询返回一个对象,要进行判断,如果是null就抛出一个异常。

PositionListBase positionListBase = positionListBaseRepository.findById(vo.getStandardPositionId());

		if(null == positionListBase){
			throw new BusinessException(ExceptionEnum.SELECT_DATA_NULL);
		}

如果返回的是一个集合,就要判断是否为空,为空就抛出异常,不为空就遍历。

List boList = positionListBaseRepository.getAllPositionListBaseByOrder();

	if(CollectionUtils.isEmpty(boList)){
		throw new BusinessException(ExceptionEnum.SELECT_DATA_NULL);
	}
for(PositionListBaseBO bo : boList){
			
		}

3.order_value是int类型的,这里做了类型转换转换成了字符串String类型的,< 3 就是小于3的意思。

  select id,company_id as companyId,list_type as listType,list_name as listName,description,order_value as orderValue,data_status as dataStatus,
        case when list_type &lt; 3 then lpad(cast (order_value as varchar), 3, '0') else lpad(cast (order_value as varchar), 4, '0') end as str
        from t_employee_position_list_base order by list_type asc,order_value asc

4.Responsebody将javabean转成json。
RequestBody将json转成javaBean。

5.分页封装的基类,通用的。

@Data
public class PageBean<T> {
    private List<T> rows;

    private int pageNum;

    private int pageSize;

    private long total;

    public PageBean () {}

    public  PageBean (PageInfo<T> pageInfo) {
        this.rows = pageInfo.getList();
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.total = pageInfo.getTotal();
    }

    public PageBean (int pageNum, int pageSize){
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = 0;
    }

}

6.所有返回值返回的基类。

public class ResultBean<T> implements Serializable {

    private String errorMessage; // 错误消息

    private int errorCode; // 错误码

    private String errorDetail; // 消息的详情信息

    private T data;


    public static <T> ResultBean build() {
        return ResultBean.build(ExceptionEnum.SUCCESS);
    }

    public static <T> ResultBean build(ExceptionEnum exceptionEnum) {
        return new ResultBean(exceptionEnum.getCode(), exceptionEnum.getMessage());
    }

    public static <T> ResultBean<T> build(T data) {
        return ResultBean.build(ExceptionEnum.SUCCESS, data);
    }

    public static <T> ResultBean<T> build(ExceptionEnum exceptionEnum, T data) {
        return ResultBean.build(exceptionEnum, null, data);
    }

    public static <T> ResultBean<T> build(ExceptionEnum exceptionEnum, String errorDetail, T data) {
        ResultBean<T> resultBean = new ResultBean<T>(exceptionEnum.getCode(), exceptionEnum.getMessage(), errorDetail, data);
        return resultBean;
    }

    public static <T> ResultBean<T> build(int errorCode, String errorMessage) {
        ResultBean<T> resultBean = new ResultBean<T>(errorCode, errorMessage);
        return resultBean;
    }

    private ResultBean(int errorCode, String errorMessage) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    private ResultBean(int errorCode, String errorMessage, String errorDetail, T data) {
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
        this.errorDetail = errorDetail;
        this.data = data;
    }


    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }

    public static void main(){

    }

}
public enum ExceptionEnum {
 POSITION_LIST_BASE_EXIST(1000015,"基准岗位名称已被更新,请刷新后重新生成职位序列"),
    POSITION_LIST_RANK_EXIST(1000016,"该职级职位序列绑定人数大于0"),
    POSITION_LIST_ALREADY_DELETED(1000017,"该职位序列已停用"),
    ;

    private int code;

    private String message;

    private ExceptionEnum(int code, String message){
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}

7.雪花算法是每秒生成26万个id左右,生成id的数量很大的。分布式雪花算法id。官网可以直接抄代码使用的。
8.src------>main----->java
src---->main----->resources----->application.yml。
9.想让方法在容器中要加个@Bean。

10.最近和前端联调的时候,报跨域的问题,通过查询资料,解决跨域问题,只需一个注解。
添加注解@CrossOrigin,此注解可以添加到类上,也可以添加到方法上

11.
@RequestBody,前端传递过来的json格式,用这个注解可以把json转换成JavaBean对象。
@ResponseBody,响应给前端的数据,将json格式转换成了javaBean的格式了。

@在这里插入图片描述
1.分布式的情况下,写的实体类比如Student这个类必须去implement Serializable,原因是可以在任何的平台下使用IO流去传输。

public class Student implement Serializable{
 private String id;
 ......
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值