download:算法面试专题课(Java版)
本套课程不讲算法基础知识,专攻算法题解。讲师作为诸多算法练习相关网站出题人,拥有多年出题及面试经验,将大厂主流经典的面试题全面归类梳理,带你掌握高效解题思路,摆脱题海,举一反三,只需20小时,完成面试准备。
Q:学这个课程需要什么基础,用的什么语言
亲,您好~语言是java,学本课程需要你掌握基本的算法与数据结构基础知识,课程全程讲解算法题解,实践为主。祝您学习愉快~
Q:请问这个课程和之前的算法课还有体系课有什么区别 专注刷题?
亲,您好~这个课程不以基础知识讲解为主,侧重解题思路,将算法思维付出实践,课程内容也汇集了常考的算法题和老师自己出的题目,尽可能做到高质量做题,尽量弄懂一类题,而不是只做会一道题。所以学习本课程需要你先掌握基础的算法与数据结构基础,学习顺序的话需要你优先掌握bobo老师的算法体系课。祝您学习愉快~
技术要求
1.掌握Java基础语法
2.掌握基本的算法与数据结构理论知识
环境参数
开发语言:Java
登錄的逻輯應該是
session中存儲用戶的主要信息
key:guid類型
value: 用戶的信息
cookie中存儲效勞端的session的數據類型
key:CurrentUser //這是一個固定的值
value: session中的key的名字
- 相關代码如下:
登錄控製器
//這是一個空過濾過濾器,表示該控製器里的都不停止過濾
[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();
}
}
辦法過濾器
///
/// 辦法過濾器///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(\"這是辦法執行後\");}}
空白過濾器,目的是爲了跳過過濾器
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;//}}