數(shù)據(jù)展示出來了诗舰,我們接下來進行修改頁面數(shù)據(jù)
- 點擊修改,在彈出框中要先把用戶信息填充進去造锅,需要一個詳情接口原献,我們先來在dao中添加一個方法
CustomerDao:
Customer queryCustomerById(Long id);
CustomerDao.xml:
<select id="queryCustomerById" parameterType="long" resultType="Customer">
SELECT * FROM customer WHERE cust_id = #{id}
</select>
Service中增加對應的方法
public Customer queryCustomerById(Long id){
return this.customerDao.queryCustomerById(id);
}
Controller中實現(xiàn)調(diào)用
@RequestMapping("/customer/edit")
@ResponseBody
public Customer queryCustomerList(@RequestParam Long id) {
return this.customerService.queryCustomerById(id);
}
根據(jù)接口返回的數(shù)據(jù)填充頁面
- 點擊保存修改,調(diào)用修改接口盐数,我們先去定義dao中的update方法
CustomerDao:
void updateCustomer(Customer customer);
CustomerDao.xml:
<select id="updateCustomer" parameterType="Customer">
UPDATE `customer`
SET
<if test="cust_name !=null and cust_name != ''">
`cust_name` = #{cust_name},
</if>
<if test="cust_user_id !=null">
`cust_user_id` = #{cust_user_id},
</if>
<if test="cust_create_id !=null">
`cust_create_id` = #{cust_create_id},
</if>
<if test="cust_source !=null and cust_source != ''">
`cust_source` = #{cust_source},
</if>
<if test="cust_industry !=null and cust_industry != ''">
`cust_industry` = #{cust_industry},
</if>
<if test="cust_level !=null and cust_level != ''">
`cust_level` = #{cust_level},
</if>
<if test="cust_linkman !=null and cust_linkman != ''">
`cust_linkman` = #{cust_linkman},
</if>
<if test="cust_phone !=null and cust_phone != ''">
`cust_phone` = #{cust_phone},
</if>
<if test="cust_mobile !=null and cust_mobile != ''">
`cust_mobile` = #{cust_mobile},
</if>
<if test="cust_zipcode !=null and cust_zipcode != ''">
`cust_zipcode` = #{cust_zipcode},
</if>
<if test="cust_address !=null and cust_address != ''">
`cust_address` = #{cust_address},
</if>
`cust_createtime` = NOW()
WHERE
(`cust_id` = #{cust_id});
</select>
在Service定義方法
public void updateCustomer(Customer customer){
this.customerDao.updateCustomer(customer);
}
在Controller中實現(xiàn)接口
@RequestMapping("/customer/update")
@ResponseBody
public String updateCustomer(Customer customer){
System.out.println("updateCustomer");
this.customerService.updateCustomer(customer);
return "OK";
}
這樣頁面修改完之后點擊修改就OK了棒拂,后面還有一個刪除,這里就不一步步說了玫氢,和修改類似帚屉,可以直接參考
總結(jié)
本系列到此結(jié)束,通過一個簡單的小型系統(tǒng)來記錄梳理一遍SpringMVC的整個開發(fā)流程漾峡。
本系列源碼存放在github上 源碼