算法面試專題課(Java版)

download:算法面試專題課(Java版)

本套課程不講算法基礎知識,專攻算法題解。講師做爲諸多算法練習相關網站出題人,擁有多年出題及面試經驗,將大廠主流經典的面試題全面歸類梳理,帶你掌握高效解題思路,擺脫題海,觸類旁通,只需20小時,完成面試準備。html

Q:學這個課程須要什麼基礎,用的什麼語言
親,您好~語言是java,學本課程須要你掌握基本的算法與數據結構基礎知識,課程全程講解算法題解,實踐爲主。祝您學習愉快~java

Q:請問這個課程和以前的算法課還有體系課有什麼區別 專一刷題?
親,您好~這個課程不以基礎知識講解爲主,側重解題思路,將算法思惟付出實踐,課程內容也聚集了常考的算法題和老師本身出的題目,儘量作到高質量作題,儘可能弄懂一類題,而不是隻作會一道題。因此學習本課程須要你先掌握基礎的算法與數據結構基礎,學習順序的話須要你優先掌握bobo老師的算法體系課。祝您學習愉快~面試

技術要求
1.掌握Java基礎語法
2.掌握基本的算法與數據結構理論知識算法

環境參數
開發語言:Java
登錄的邏輯應該是
session中存儲用戶的主要信息
key:guid類型
value: 用戶的信息
cookie中存儲效勞端的session的數據類型
key:CurrentUser //這是一個固定的值
value: session中的key的名字cookie

  1. 相關代碼以下:

登錄控製器session

//這是一個空過濾過濾器,表示該控製器裏的都不中止過濾
[CustomAllowAnonymous]
public class SessionLoginController : Controller
{
[HttpGet]
public IActionResult SessionLogins(int a)
{
if (a == 1)
{
#region Cookie/Session 本人寫 普通運用Sessio爲主
CurrentUser currentUser = new CurrentUser()
{
Id = 123,
Name = "wangjin",
Account = "Administrator",
Email = "1293604064",
Password = "123456",
LoginTime = DateTime.Now
};
//生成一個guid的值用來存儲主鍵的值
Guid sessionKey = Guid.NewGuid();
//寫Session/寫Cookies
base.HttpContext.SetCookies("CurrentUser", sessionKey.ToString(), 30);
//寫入session
base.HttpContext.Session.SetString(sessionKey.ToString(), Newtonsoft.Json.JsonConvert.SerializeObject(currentUser));
#endregion
return base.Redirect("/Home/Index");
}
return View();
}
}
辦法過濾器數據結構

/// app

/// 辦法過濾器
/// 
public class CustomActionFilterAttribute : Attribute, IActionFilter
{
    /// 

    /// 辦法執行前
    /// 
    /// 
    public void OnActionExecuting(ActionExecutingContext context)
    {
        //表示假如帶有該屬性,就不中止下面的步驟,直接返回
        if (context.ActionDescriptor.EndpointMetadata.Any(item => item.GetType() == typeof(CustomAllowAnonymousAttribute))) //假如標誌的有特殊的記號,就避開檢查;
        {
            return;
        }
        Byte[] bytes;
        context.HttpContext.Session.TryGetValue("CurrentUser", out bytes);
        string cookieKey = CookieSessionHelper.GetCookiesValue(context.HttpContext, "CurrentUser");
        string str = cookieKey != null ? new SessionHelper(context.HttpContext).GetSession(cookieKey) : null;
        if (string.IsNullOrEmpty(str))
        {
            var result = new ViewResult { ViewName = "~/Views/SessionLogin/SessionLogins.cshtml" };
            //result.ViewData = new ViewDataDictionary(_modelMetadataProvider, context.ModelState);
            //result.ViewData.Add("Exception", context.Exception);
            context.Result = result; //斷路器---只需對Result賦值--就不繼續往後了;
        }
        Console.WriteLine("這是辦法執行前");
    }
    /// 

    /// 辦法執行後
    /// 
    /// 
    public void OnActionExecuted(ActionExecutedContext context)
    {
        if (context.ActionDescriptor.EndpointMetadata.Any(item => item.GetType() == typeof(CustomAllowAnonymousAttribute))) //假如標誌的有特殊的記號,就避開檢查;
        {
            return;
        }
        Console.WriteLine("這是辦法執行後");
    }
}

空白過濾器,目的是爲了跳過過濾器ide

public class CustomAllowAnonymousAttribute:Attribute
{
}
在ConfigureServices中添加以下:學習

services.AddSession();
services.AddMvc(option =>
{
option.Filters.Add(); //全局註冊:
option.Filters.Add(); //全局註冊異常過濾器:
});
在Configure中添加以下:

        app.UseSession();
app.UseCookiePolicy();
還有操做cookie封裝的辦法:

public static class CookieSessionHelper
{
public static void SetCookies(this HttpContext httpContext, string key, string value, int minutes = 30)
{
httpContext.Response.Cookies.Append(key, value, new CookieOptions
{
Expires = DateTime.Now.AddMinutes(minutes)
});
}
public static void DeleteCookies(this HttpContext httpContext, string key)
{
httpContext.Response.Cookies.Delete(key);
}
public static string GetCookiesValue(this HttpContext httpContext, string key)
{
httpContext.Request.Cookies.TryGetValue(key, out string value);
return value;
}
public static CurrentUser GetCurrentUserBySession(this HttpContext context)
{
string sUser = context.Session.GetString("CurrentUser");
if (sUser == null)
{
return null;
}
else
{
CurrentUser currentUser = Newtonsoft.Json.JsonConvert.DeserializeObject(sUser);
return currentUser;
}
}
}
封裝操做Session的

public class SessionHelper
{
private IHttpContextAccessor _accessor;
private ISession _session;
private IRequestCookieCollection _requestCookie;
private IResponseCookies _responseCookie;
public SessionHelper(HttpContext context)
{
_session = context.Session;
_requestCookie = context.Request.Cookies;
_responseCookie = context.Response.Cookies;
}
///

/// 設置session值
    /// 
    /// 
    /// 鍵
    /// 值
    public void SetSession(string key, string value)
    {
        var bytes = System.Text.Encoding.UTF8.GetBytes(value);
        _session.Set(key, bytes);
    }
    /// 

    /// 獲取Session值
    /// 
    /// 
    /// 
    public string GetSession(string key)
    {
        Byte[] bytes;
        _session.TryGetValue(key, out bytes);
        var value = System.Text.Encoding.UTF8.GetString(bytes);
        if (string.IsNullOrEmpty(value))
        {
            value = string.Empty;
        }
        return value;
    }
    ///// 

    ///// 設置本地cookie
    ///// 
    ///// 鍵
    ///// 值
    ///// 過時時間
    //public void SetCookies(string key,string value,int day = 1)
    //{
    //    _responseCookie.Append(key, value, new CookieOptions
    //    {
    //        Expires = DateTime.Now.AddDays(day)
    //    }) ;
    //}
    //public void  DeleteCookies(string key)
    //{
    //    _responseCookie.Delete(key);
    //}
    //public string GetCookiesValue(string key)
    //{
    //    _requestCookie.TryGetValue(key, out string value);
    //    if (string.IsNullOrEmpty(value))
    //    {
    //        value = string.Empty;
    //    }
    //    return value;
    //}
}
相關文章
相關標籤/搜索