All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.tenfell.tools.nocontroller.component.BaseService Maven / Gradle / Ivy

The newest version!
package cn.tenfell.tools.nocontroller.component;

import cn.hutool.core.lang.Assert;
import cn.tenfell.tools.nocontroller.utilsentity.R;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class BaseService {
    public  R page(T data,Long total) {
        return R.page(data,total);
    }
    public  R ok() {
        return R.ok();
    }
    public  R okData(T data) {
        return R.okData(data);
    }
    public  R ok(String msg) {
        return R.ok(msg);
    }
    public  R ok(T data,String msg) {
        return R.ok(data,msg);
    }
    public  R failed() {
        return R.failed();
    }
    public  R failed(String msg) {
        return R.failed(msg);
    }
    public  T getUser(){
        Assert.notNull(UriHandComponent.getNoControllerInterface());
        return (T)UriHandComponent.getNoControllerInterface().getLoginUser(getRequest());
    }
    public HttpServletRequest getRequest(){
        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
        Assert.notNull(ra);
        HttpServletRequest request = ((ServletRequestAttributes) ra).getRequest();
        return request;
    }
    public HttpSession getSession() {
        HttpServletRequest request = getRequest();
        Assert.notNull(request);
        HttpSession session = request.getSession();
        return session;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy