標籤:
一、建立資料庫(環境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;
}
}
三、業務開發初步