目录
基本和用户功能相同
一.客户添加
1.1客户实体类
1.2前端
1.2.1添加用户页面
1.2.2代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加客户</title>
<!--导入bootstrap依赖 -->
<link rel="stylesheet" href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="assets/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--导入Vue依赖-->
<script src="assets/vue.min-v2.5.16.js"></script>
<script src="assets/axios.min.js"></script>
<style>
a:link{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:visited{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:hover{
font-size: 20px;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container" id="app">
<!-- bootstrap行-->
<div class="row">
<!-- 显示导航-->
<div class="col-md-3" style="background-color: rgb(0,21,41); height: 800px;">
<!-- bootstrap行 -->
<div class="row">
<div class="col-md-12" style="background-color: rgb(0,40,77); text-align: center; height: 70px; line-height: 70px; font-size: 20px; color: white; font-weight: bold">
<img src="assets/img/logo.png" style="width: 30px; height: 30px; margin-right: 8px"/>
蜗牛CRM管理系统
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="index.html">进入首页</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="user_list.html">用户管理</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="user_add.html">添加用户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="custom_list.html">客户管理</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="custom_add.html">添加客户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="#">修改密码</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center; padding: 20px 0px 20px 0px">
<a href="login.html">退出登录</a>
</div>
</div>
</div>
<!-- 显示内容 -->
<div class="col-md-9" style="border: 1px solid gray; height: 800px">
<div class="row">
<!-- 显示提示位置 -->
<div class="col-md-12" style="height: 70px; color: rgb(109,109,109); font-size: 18px; line-height: 70px; font-weight: bold; padding-left: 20px">
> 添加客户
</div>
</div>
<!-- 显示内容 -->
<div class="row" style="background-color: rgb(240,242,245); height: 730px; padding: 20px">
<div class="col-md-12" style="background-color: white; height: 730px; border: none; border-radius: 5px;">
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 50px">
<label>客户名</label>
<input type="text" class="form-control" v-model="customName"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>年龄</label>
<input type="text" class="form-control" v-model="age"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>手机号</label>
<input type="text" class="form-control" v-model="phone"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>微信</label>
<input type="text" class="form-control" v-model="wechat"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>邮箱</label>
<input type="text" class="form-control" v-model="email"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>住址</label>
<input type="text" class="form-control" v-model="addr"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>爱好</label>
<input type="text" class="form-control" v-model="hoby"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label>职业</label>
<input type="text" class="form-control" v-model="occupation"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px">
<label style="margin-right: 15px">性别</label>
<label class="radio-inline">
<input type="radio" value="0" v-model="sex" name="sex"/>男
</label>
<label class="radio-inline">
<input type="radio" value="1" v-model="sex" name="sex"/>女
</label>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4" style="margin-top: 20px; text-align: center">
<button class="btn btn-primary" style="margin-right: 8px" @click="doAdd">添加</button>
<button class="btn btn-default">重置</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
//创建vue实例
new Vue({
el: '#app',
data: {
customName: null,
age: null,
sex: null,
phone: null,
wechat: null,
addr: null,
hoby: null,
email: null,
occupation: null
},
methods: {
doAdd(){
var url = "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;
//通过axios发送请求到servlet
axios.get(url).then(response => {
if(response.data == '保存成功'){
window.location.href = 'custom_list.html';
} else {
alert("添加用户失败!!!");
}
});
}
}
});
</script>
</body>
</html>
1.3后端
1.3.1添加用户方法
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()+")";
return this.executeUpdate(sql);
}
1.3.2添加用户Servlet
package controller;
import com.alibaba.fastjson.JSON;
import dao.CustomDAO;
import dao.impl.CustomDAOImpl;
import entity.Custom;
import entity.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.util.List;
/**
* 查询全部客户
*/
@WebServlet("/custom_list")
public class CustomListServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//译码码集,解决中文乱码问题
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("application/json;charset=utf8");
//获取打印输出流,向网页输出内容
PrintWriter writer = resp.getWriter();
//从session中获取用户信息,是不是admin用户
HttpSession session = req.getSession();
User user = (User) session.getAttribute("user");
//通过dao查询客户列表
CustomDAO dao = new CustomDAOImpl();
List<Custom> list = null;
if ("admin".equals(user.getUserName())){
//显示全部的客户信息
list = dao.selectAllCustom();
}else{
//显示当前登录的用户自己的客户信息
list = dao.selectCustomByUid(user.getId());
}
//向页面输出客户信息
String json = JSON.toJSONString(list);//将list对象转为json
writer.print(json);
//释放资源
writer.close();
}
}
二.客户列表
2.1前端
2.1.1显示用户页面
2.1.2代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>客户管理</title>
<!--导入bootstrap依赖 -->
<link rel="stylesheet" href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="assets/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--导入Vue依赖-->
<script src="assets/vue.min-v2.5.16.js"></script>
<script src="assets/axios.min.js"></script>
<style>
a:link{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:visited{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:hover{
font-size: 20px;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container" id="app">
<!--行-->
<div class="row">
<!--登录导航-->
<div class="col-md-3" style="background-color:rgb(0,21,41);height: 800px">
<!--行-->
<div class="row">
<div class="col-md-12" style="background-color:rgb(0,40,77);text-align: center;height: 70px;line-height: 70px;font-size: 20px;color:white;font-weight: bold;">
<img src="assets/img/logo.png" style="width: 30px;height: 30px;margin-right: 8px;">
蜗牛CRM管理系统
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="index.html">进入首页</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="user_list.html">用户管理</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="user_add.html">添加用户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="custom_list.html">客户管理</a>
</div>
</div>
<div class="custom_add.html">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="custom_add.html">添加客户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="update_passwd.html">修改密码</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="login.html">退出登陆</a>
</div>
</div>
</div>
<!--登录内容-->
<div class="col-md-9" style="border: 1px solid gray;height: 800px">
<!--显示提示位置-->
<div class="row">
<div class="col-md-12"style="height: 70px;color:rgb(109,109,109);font-size: 18px; line-height: 70px;font-weight: bold;padding-left: 20px;">
> 客户管理
</div>
</div>
<!--显示内容-->
<div class="row" style="background-color:rgb(240,242,245);height: 730px;padding: 20px 20px 20px 20px;">
<div class="col-md-12" style="background-color: white;height: 730px;border: none;border-radius: 5px;">
<!--使用bootstrap表格样式-->
<table class="table table-striped" style="margin-top: 20px;">
<!--表格描述-->
<caption>客户管理-客户列表</caption>
<!--表头-->
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>手机号</th>
<th>微信号</th>
<th>住址</th>
<th>爱好</th>
<th>邮箱</th>
<th>职业</th>
<th>创建者</th>
<th>操作</th>
</tr>
</thead>
<!--表格内容-->
<tbody>
<tr v-for="c in customs">
<td>{{c.id}}</td>
<td>{{c.name}}</td>
<td>{{c.age}}</td>
<td>{{c.sex==0?'男':'女'}}</td>
<td>{{c.phone}}</td>
<td>{{c.wechat}}</td>
<td>{{c.addr}}</td>
<td>{{c.hoby}}</td>
<td>{{c.email}}</td>
<td>{{c.occupation}}</td>
<td>{{c.nickName}}</td>
<td>
<button class="btn btn-link"@click="doUpdate(c.id)">修改</button>
<button class="btn btn-link" @click="doDelete(c.id)">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<script>
new Vue({
el:'#app',
data:{
customs:null
},
created:function () {//页面加载完成之后执行
this.requstCustomList();//请求用户列表的函数
},
methods: {
//删除用户,根据id
doDelete(id) {
//console.log("要删除的用户id:"+id)//打印控制台
//请求servlet删除用户
axios.get("delete_custom?id="+id).then(res => {
if (res.data == '删除成功'){
this.requstCustomList();//请求用户列表的函数
}else{
alert("删除失败!!!")
}
});
},
doUpdate(id){//点击修改按钮触发
//跳转到user_update.html页面,并且传递id过去
window.location.href = "custom_update.html?id="+id;
},
requstCustomList(){
//发送请求获取客户列表
axios.get("custom_list").then(response => {
this.customs = response.data;
});
}
}
});
</script>
</body>
</html>
2.2后端
1.2.1显示客户列表方法
public List<Custom> selectAllCustom() {
String sql = "SELECT c.*, u.nick_name FROM t_custom AS c LEFT JOIN t_user AS u ON c.uid=u.id";
ResultSet rs = this.executeQuery(sql);
List<Custom> list = new ArrayList<Custom>(); //用于保存所有客户信息
try {
while(rs.next()){
Custom custom = new Custom();
custom.setId(rs.getInt("id"));
custom.setName(rs.getString("name"));
custom.setAge(rs.getInt("age"));
custom.setSex(rs.getInt("sex"));
custom.setPhone(rs.getString("phone"));
custom.setWechat(rs.getString("wechat"));
custom.setAddr(rs.getString("addr"));
custom.setHoby(rs.getString("hoby"));
custom.setEmail(rs.getString("email"));
custom.setOccupation(rs.getString("occupation"));
custom.setUid(rs.getInt("uid"));
custom.setNickName(rs.getString("nick_name"));
list.add(custom);
}
this.closeAll();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
return list;
}
1.2.2显示客户列表Servlet
package controller;
import com.alibaba.fastjson.JSON;
import dao.CustomDAO;
import dao.impl.CustomDAOImpl;
import entity.Custom;
import entity.User;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.util.List;
/**
* 查询全部客户
*/
@WebServlet("/custom_list")
public class CustomListServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//译码码集,解决中文乱码问题
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("application/json;charset=utf8");
//获取打印输出流,向网页输出内容
PrintWriter writer = resp.getWriter();
//从session中获取用户信息,是不是admin用户
HttpSession session = req.getSession();
User user = (User) session.getAttribute("user");
//通过dao查询客户列表
CustomDAO dao = new CustomDAOImpl();
List<Custom> list = null;
if ("admin".equals(user.getUserName())){
//显示全部的客户信息
list = dao.selectAllCustom();
}else{
//显示当前登录的用户自己的客户信息
list = dao.selectCustomByUid(user.getId());
}
//向页面输出客户信息
String json = JSON.toJSONString(list);//将list对象转为json
writer.print(json);
//释放资源
writer.close();
}
}
三.修改
3.1修改
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改用户</title>
<!--导入bootstrap依赖 -->
<link rel="stylesheet" href="assets/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="assets/jquery-3.5.1/jquery-3.5.1.min.js"></script>
<script src="assets/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!--导入Vue依赖-->
<script src="assets/vue.min-v2.5.16.js"></script>
<script src="assets/axios.min.js"></script>
<style>
a:link{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:visited{
font-size: 20px;
color: rgb(109, 109, 109);
}
a:hover{
font-size: 20px;
color: white;
text-decoration: none;
}
</style>
</head>
<body>
<div class="container" id="app">
<!--行-->
<div class="row">
<!--登录导航-->
<div class="col-md-3" style="background-color:rgb(0,21,41);height: 800px">
<!--行-->
<div class="row">
<div class="col-md-12" style="background-color:rgb(0,40,77);text-align: center;height: 70px;line-height: 70px;font-size: 20px;color:white;font-weight: bold;">
<img src="assets/img/logo.png" style="width: 30px;height: 30px;margin-right: 8px;">
蜗牛CRM管理系统
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="index.html">进入首页</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="user_list.html">用户管理</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="user_add.html">添加用户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="custom_list.html">客户管理</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="custom_add.html">添加客户</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="update_passwd.html">修改密码</a>
</div>
</div>
<div class="row">
<div class="col-md-12" style="text-align: center;padding: 20px 0px 20px 0px;">
<a href="login.html">退出登陆</a>
</div>
</div>
</div>
<!--登录内容-->
<div class="col-md-9" style="border: 1px solid gray;height: 800px">
<!--显示提示位置-->
<div class="row">
<div class="col-md-12"style="height: 70px;color:rgb(109,109,109);font-size: 18px; line-height: 70px;font-weight: bold;padding-left: 20px;">
> 修改用户
</div>
</div>
<!--显示内容-->
<div class="row" style="background-color:rgb(240,242,245);height: 730px;padding: 20px 20px 20px 20px;">
<div class="col-md-12" style="background-color: white;height: 730px;border: none;border-radius: 5px;">
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 50px;">
<label>用户名</label>
<input type="text" class="form-control" v-model="userName" />
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 20px;">
<label>昵称</label>
<input type="text" class="form-control" v-model="nickName"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 20px;">
<label>手机号</label>
<input type="text" class="form-control"v-model="phone"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 20px;">
<label>生日</label>
<input type="text" class="form-control" v-model="birth"/>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 20px;">
<label style="margin-right:15px ">性别</label>
<label class="radio-inline">
<input type="radio" value="0" v-model="sex" name="sex"/>男
</label>
<label class="radio-inline">
<input type="radio" value="1" v-model="sex" name="sex"/>女
</label>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4"style="margin-top: 20px;text-align: center">
<button class="btn btn-primary" style="margin-right: 8px" @click="doUpdate">修改</button>
<button class="btn btn-default" @click="doRest">重置</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
//创建vue实例
new Vue({
el: '#app',
data: {
id:null,
userName: null,
nickName: null,
sex: null,
phone: null,
birth: null
},
methods: {
doUpdate(){
var url = "user_update?id="+this.id+"&user_name="+this.userName+"&nick_name="+this.nickName+"&sex="+this.sex
+"&phone="+this.phone+"&birth="+this.birth;
//通过axios发送请求到servlet
axios.get(url).then(response=>{
if (response.data == '修改成功'){
window.location.href = 'user_list.html';
}else{
alert("修改失败");
}
});
},
doRest(){
this.userName = null;
this.nickName = null;
this.sex= null;
this.phone = null;
this.birth = null;
}
},
created: function () { //页面加载完成后触发
var url = window.location.href; //获取网页的url地址
// console.log(url);
var id = url.substring(url.indexOf("=")+1);
this.id=id;
// console.log(temp);
//通过axios发送请求获取用户信息
axios.get("user_info?id="+id).then(response => {
console.log(response.data);
this.userName = response.data.userName;
this.nickName = response.data.nickName;
this.sex = response.data.sex;
this.phone = response.data.phone;
this.birth = response.data.birth;
});
}
});
</script>
</body>
</html>