Mvc5做的增删改查

最近公司做项目,架构是mvc5  .net core,开发工具是vs2015.

1.前台列表页面

@*
    For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@{

    ViewBag.Title = "Index";
    Layout = "../Shared/_Layout.cshtml";

}

@model List<InfoManagerDAL.AdvertisementDAL>
<form id="form1">
    <div><a href="/Advertise/Addinfo">新增</a></div>
    <div>
        <h2>广告列表</h2>
        <table>
            <tr>
                <th>编号</th>
              
                <th>图片</th>
                <th>作者</th>
                <th>添加日期</th>

                <th>操作</th>
            </tr>
            @if (Model == null)
            {
                <tr>
                    <td colspan="6">暂无图片</td>
                </tr>
            }

        else
        {
                foreach (var adver in Model)
                {
                    <tr>
                        <td>@adver.ID</td>
                     
                        <td> <img src="@adver.ImageName"></td>
                        <td>@adver.Creater</td>
                        <td>@adver.Addtime</td>
                        <td><a href="/Advertise/Update/@adver.ID">修改</a>
                        <a href="javascript:void(0);" οnclick="del('@adver.ID');">删除</a>
                        
                        </td>
                    </tr>
            }
        }
        </table>


    </div>

</form>

<script type="text/javascript">

    function del(id)
    {
        $.dialog({
            content: '是否确定删除吗?',
            ok: function(){
                $.ajax({
                    type: "delete",
                    url: "/Advertise/delete/" + id,
                    contentType: "application/json",
                    dataType: "json",
                    async: true,
                    success: function (result) {
                        if (result.value.isSuccess) {
                            alert("删除成功!");
                            setTimeout(function () {location.href = result.value.backurl; }, 500);
                        } else
                            alert(result.value.msg);
                    }
                });
                return false;
            },
            cancelVal: '关闭',
            cancel: true /*为true等价于function(){}*/
        });

    }

</script>

B。添加页面

@*
    For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    ViewBag.Title = "Index";
    Layout = "../Shared/_Layout.cshtml";
}


<form method="post" enctype="multipart/form-data">

    <h2>添加广告</h2>
    图片:<input type="file" id="files"  name="fi

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MVC模式的实现对数据库的增删改查 部分代码: package dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import common.DBConnection; import bean.Contact; public class ContactDAO { public List getAllContact() throws Exception{ Connection conn=DBConnection.getConntion(); PreparedStatement ps=conn.prepareStatement("select * from Contact"); ResultSet rs=ps.executeQuery(); List list = new ArrayList(); while(rs.next()){ int id = rs.getInt("id"); String name = rs.getString("name"); String phone = rs.getString("phone"); String address = rs.getString("address"); Contact c = new Contact(); c.setId(id); c.setName(name); c.setPhone(phone); c.setAddress(address); list.add(c); } rs.close(); ps.close(); conn.close(); return list; } public void addContact(String name,String phone,String address) throws Exception{ String sql = "insert into contact(id,name,phone,address) values(seq_contact.nextval,?,?,?)"; Connection con = DBConnection.getConntion(); PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, name); pstmt.setString(2, phone); pstmt.setString(3, address); pstmt.executeUpdate(); } public void delContact(int id) throws Exception{ String sql = "delete from contact where id=?"; Connection con = DBConnection.getConntion(); PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setInt(1, id); pstmt.executeUpdate(); } public Contact getContactById(int id) throws Exception{ String sql = "select * from Contact where id=?"; Connection con = DBConnection.getConntion(); PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); Contact c = null; while(rs.next()){ // int id = rs.getInt("id"); String name=rs.getString("name"); String p

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值