CRM管理系统添加客户

一、后端servlet开发

1.1、创建Custom实体类

public class Custom {
    private  int id;
    private String name;
    private int age;
    private int  Sex;
    private String phone;
    private String wechat;
    private String addr;
    private String hoby;
    private String email;
    private String occupation;
    private  int uid;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSex() {
        return Sex;
    }

    public void setSex(int sex) {
        Sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getWechat() {
        return wechat;
    }

    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getHoby() {
        return hoby;
    }

    public void setHoby(String hoby) {
        this.hoby = hoby;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getOccupation() {
        return occupation;
    }

    public void setOccupation(String occupation) {
        this.occupation = occupation;
    }

    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }
}

1.2、创建CustomDAO,新增用户的方法

public class CustomDAOImpl extends BaseDAO implements CustomDAO {
    public int insertCustom(Custom custom) {
        String sql = "insert into t_custom (name,age,sex,phone,wechat,addr,hoby,email,occupation,uid) values ('"+custom.getName()+"',"+custom.getAge()+","+custom.getSex()+",'"+custom.getPhone()+"','"+custom.getWechat()+"','"+custom.getAddr()+"','"+custom.getHoby()+"','"+custom.getEmail()+"', '"+custom.getOccupation()+"',"+custom.getUid()+")";        int count = this.executeUpdate(sql);
        return count;
    }
}

1.3、创建CustomAddServlet

第1步:在session中获取用户id

//从session中获取用户的id
HttpSession session = req.getSession();
Manger manger =(Manger) session.getAttribute("user");
    int uid=manger.getId();

第2步:将用户信息通过dao保存到数据库

 CustomDAO dao=new CustomDAOImpl();
    //获取请求传参
    String name = req.getParameter("name");
    int age = Integer.parseInt(req.getParameter("age"));
    int sex = Integer.parseInt(req.getParameter("sex"));
    String phone = req.getParameter("phone");
    String wechat = req.getParameter("wechat");
    String addr = req.getParameter("addr");
    String hoby = req.getParameter("hoby");
    String email = req.getParameter("email");
    String occupation = req.getParameter("occupation");

    Custom custom = new Custom();
    custom.setName(name);
    custom.setAge(age);
    custom.setSex(sex);
    custom.setPhone(phone);
    custom.setWechat(wechat);
    custom.setAddr(addr);
    custom.setHoby(hoby);
    custom.setEmail(email);
    custom.setOccupation(occupation);
    custom.setUid(uid);
    int count = dao.insertCustom(custom);
    if(count>0){
        writer.print("保存成功");
    }else{
        writer.print("保存失败");
    }


    writer.close();//释放资源
}

二、前端HTML开发

2.1、通过vue的双向绑定收集用户信息

data:{
    customName: null,
    age: null,
    sex: null,
    phone: null,
    wechat: null,
    addr: null,
    hoby: null,
    email: null,
    occupation: null
},

2.2、给添加按钮绑定点击事件

<button class="btn btn-primary" style="margin-right: 8px;" @click="doAdd()">添加</button>

2.3、通过axios发送请求访问servlet添加客户

doAdd(){
    var url = "http://localhost:8080/custom_add?name="+this.customName+"&age="+this.age+"&sex="+this.sex+"&phone="+this.phone+"&wechat="+this.wechat+"&addr="+this.addr+"&hoby="+this.hoby+"&email="+this.email+"&occupation="+this.occupation;
    console.log(url);
    axios.get(url).then(response=>{
        if(response.data=="保存成功"){
            alert("自己查数据库");
            //window.location.href="user_list.html"
        }else{
            alert('添加失败!!!');
        }
    })
},
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值