• ASP.Net 反射简单


    Contorller中

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using G3.IDAL;
    using G6.Model;
    using Microsoft.AspNetCore.Mvc;

    namespace G6.WeekOne.MVC.Controllers
    {
    public class UserController : Controller
    {
    public IActionResult Index()
    {

    List<UsersModel> list = new List<UsersModel>();
    return View(list);
    }
    /// <summary>
    /// 跳转到用户添加页面
    /// </summary>
    /// <returns></returns>
    public IActionResult AddUser() => View();

    /// <summary>
    /// 添加用户
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public int AddUser(UsersModel model)
    {
    IUserDAL dal = Factory.CreateInstance("sql");
    return dal.AddUser<UsersModel>(model);
    }

    }

    DBConnection

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using MySql.Data.MySqlClient;

    namespace G6.DAL
    {
    public abstract class DBConnection
    {
    private static string conSql= "Data Source=.;Initial Catalog=G6_WeekDB;Integrated Security=True";
    private static string conMySql= "";

    public static IDbConnection GetConnection(string type)
    {
    IDbConnection connection = null;
    if (type.Equals("sql"))
    {
    connection = new SqlConnection(conSql);
    }
    else {
    connection = new MySqlConnection(conMySql);
    }
    if (connection.State == ConnectionState.Closed)
    {
    connection.Open();
    }
    return connection;
    }
    }
    }

    IDAL中

    using System;
    using System.Collections.Generic;
    using G6.Model;

    namespace G3.IDAL
    {
    public interface IUserDAL
    {
    int AddUser<T>(T model) where T:class,new();

    List<T> GetList<T>() where T : class, new();
    }
    }

  • 相关阅读:
    PHP返回随机颜色
    SQL Server 系统表介绍:sys.dm_exec_requests
    ORA27300 ORA27301 ORA27302 ORA27157
    Linux的subversion安装配置
    批处理计算n天前\后的日期
    Linux下vsftp配置
    RedHat Linux 5企业版开启VNCSERVER远程桌面功能
    WAS 6.1命令行(静默)安装
    五板斧封杀Windows操作系统默认共享(图)
    Select Top在不同数据库中的使用用法:
  • 原文地址:https://www.cnblogs.com/XJNB/p/13150333.html
Copyright © 2020-2023  润新知