一、创建数据库(环境Mysql)
Database Name(略)、Character(UTF-8 Unicode)
二、创建MVC结构
创建java/com.itemname.module(demo)包
包下创建文件夹Controller、Model、Service子包
三、编写Model层
new java class:Customer
public class Customer {
private long CustomerID;
private String Name;
private String Contact;
private String Telephone;
private String Email;
private String Remark;
//Getter and Setter
}
创建相应的数据库表并插入demo数据
三、编写控制器层
列表界面:GET:/customer
查询动作:POST:/customer_search --
详情界面:GET:/customer_show?id={id}
新建界面:GET:/customer_create
新建动作:POST:/customer_create
编辑界面:GET:/customer_edit?id={id}
编辑动作:PUT:/customer_edit?id={id}
删除动作:DELETE:/customer_delete?id={id}
对应5个Servlet
CustomerServlet、CustomerShowServlet、CustomerCreateServlet、CustomerEditServlet、CustomerDeleteServlet
创建Servlet。
@WebServlet("/customer_create")
public class CustomerCreateServlet extends HttpServlet {
/**
* 处理 创建客户 请求
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//TODO
}
/**
* 进入 创建客户 界面
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//TODO
}
}
四、编写服务层
public class CustomerService {
/**
* 获取客户列表
*/
public List<Customer> GetCustomerList(String keyword) {
//TODO
return null;
}
/**
* 获取客户
*/
public Customer GetCustomer(long id){
//TODO
return null;
}
/**
* 创建客户
*/
public boolean CreateCustomer(Map<String,Object> fieldMap){
//TODO
return false;
}
/**
* 更新客户
*/
public boolean UpdateCustomer(long id, Map<String,Object> fieldMap){
//TODO
return false;
}
/**
* 删除客户
*/
public boolean DeleteCustomer(long id){
//TODO
return false;
}
}