在2019年底项目结束,因为是在某通外包公司,所以项目组不需要我了,只能每天去某通正常打卡上下班(因为快过年了,所有打算过完年在找工作现在先在这里闲着学习充电)。外包公司不可能会全额公司养着闲人。。。。。在这里告诫大家,一定别去外包。
自己写了点东西,项目结构如图:数据库用的是sqlite数据库,因为这样可以让看到这个项目的人直接调试程序,看到效果。
.db文件就是数据库,但是使用的时候,需要引用sqlite.dll
文件在---AHao\AHao.Web\bin目录下
这个项目是一个简单登录-注销-发表内容-删除内容的程序。有兴趣的可以自行扩展其他功能,由于作者对前端css样式不太熟悉,界面比较丑,但是功能都有,大家见谅。
项目的主页展示如上图
数据库连接字符串,要根据自己的实际路径配置。在web.config文件中。如图:
源码下载地址放到百度网盘里了,因为csdn下载需要积分
部分代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace AHao.Web.Controllers
{
/// <summary>
/// 发表文章
/// </summary>
public class PostController : Controller
{
public ActionResult Index(int id)
{
//根据id去数据库查找对应的信息
Model.Post post = postBll.GetModel(id);//没有缓存
//Model.Post post = postBll.GetModelByCache(id);//从缓存中取数据
ViewData["article"] = post;
return View();
}
public ActionResult Publish()//发表
{
return View();
}
Business.Post postBll = new Business.Post();
public ActionResult DoPublish()
{
string title = Request.Form["title"];
string content = Request.Form["content"];
Model.User user = (Model.User)Session["user"];
Model.Post post = new Model.Post
{
Title = title + "-" + user.Name,
Content = content,
AddTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
};
int id = postBll.Add(post);
return new RedirectResult("/Home/Index"); //RedirectToAction("Index", "Post", new { id = id });
}
public ActionResult Delte(int id)
{
bool res = true;
res = postBll.Delete(id);
if (res)
{
return new RedirectResult("/Home/Index");
}
else
{
return new RedirectResult("/Account/Index");
}
}
}
}
下载地址链接:https://pan.baidu.com/s/1VcxTlFbgJ8YVXb5SPqsTMw
提取码:9rh7