傳智健康項目
- 黑馬程序員-傳智健康項目(第一章)
- 黑馬程序員-傳智健康項目(第二章)
- 黑馬程序員-傳智健康項目(第三章)
- 黑馬程序員-傳智健康項目(第四章)
- 黑馬程序員-傳智健康項目(第五章)
- 黑馬程序員-傳智健康項目(第六章)
- 黑馬程序員-傳智健康項目(第七章)
- 黑馬程序員-傳智健康項目(第八章)
- 黑馬程序員-傳智健康項目(第九章)
- 黑馬程序員-傳智健康項目(第十章)
- 黑馬程序員-傳智健康項目(第十一章)
- 黑馬程序員-傳智健康項目(第十二章)
- 黑馬程序員-傳智健康項目(第十三章)
- 黑馬程序員-傳智健康項目資料
第2章 預約管理-檢查項管理
1. 需求分析
傳智健康管理系統是一款應用於健康管理機構的業務系統,實現健康管理機構工作內容可視化、患者管理專業化、健康評估數字化、健康干預流程化、知識庫集成化,從而提高健康管理師的工作效率,加強與患者間的互動,增強管理者對健康管理機構運營情況的了解。
系統分為傳智健康后台管理系統和移動端應用兩部分。其中后台系統提供給健康管理機構內部人員(包括系統管理員、健康管理師等)使用,微信端應用提供給健康管理機構的用戶(體檢用戶)使用。
本項目功能架構圖:
通過上面的功能架構圖可以看到,傳智健康后台管理系統有會員管理、預約管理、健康評估、健康干預等功能。移動端有會員管理、體檢預約、體檢報告等功能。后台系統和移動端應用都會通過Dubbo調用服務層發布的服務來完成具體的操作。本項目屬於典型的SOA架構形式。
本章節完成的功能開發是預約管理功能,包括檢查項管理、檢查組管理、體檢套餐管理、預約設置等(參見產品原型)。預約管理屬於系統的基礎功能,主要就是管理一些體檢的基礎數據。
2. 基礎環境搭建
2.1 導入預約管理模塊數據表
操作步驟:
(1)根據資料中提供的itcasthealth.pdm文件導出SQL腳本
(2)創建本項目使用的數據庫itcast_health
(3)將PowerDesigner導出的SQL腳本導入itcast_health數據庫進行建表
2.2 導入預約管理模塊實體類
將資料中提供的POJO實體類復制到health_common工程中。
2.3 導入項目所需公共資源
項目開發過程中一般會提供一些公共資源,供多個模塊或者系統來使用。
本章節我們導入的公共資源有:
(1)返回消息常量類MessageConstant,放到health_common工程中
package com.itheima.constant;
/**
* 消息常量
*/
public class MessageConstant {
public static final String DELETE_CHECKITEM_FAIL = "刪除檢查項失敗";
public static final String DELETE_CHECKITEM_SUCCESS = "刪除檢查項成功";
public static final String ADD_CHECKITEM_SUCCESS = "新增檢查項成功";
public static final String ADD_CHECKITEM_FAIL = "新增檢查項失敗";
public static final String EDIT_CHECKITEM_FAIL = "編輯檢查項失敗";
public static final String EDIT_CHECKITEM_SUCCESS = "編輯檢查項成功";
public static final String QUERY_CHECKITEM_SUCCESS = "查詢檢查項成功";
public static final String QUERY_CHECKITEM_FAIL = "查詢檢查項失敗";
public static final String UPLOAD_SUCCESS = "上傳成功";
public static final String ADD_CHECKGROUP_FAIL = "新增檢查組失敗";
public static final String ADD_CHECKGROUP_SUCCESS = "新增檢查組成功";
public static final String DELETE_CHECKGROUP_FAIL = "刪除檢查組失敗";
public static final String DELETE_CHECKGROUP_SUCCESS = "刪除檢查組成功";
public static final String QUERY_CHECKGROUP_SUCCESS = "查詢檢查組成功";
public static final String QUERY_CHECKGROUP_FAIL = "查詢檢查組失敗";
public static final String EDIT_CHECKGROUP_FAIL = "編輯檢查組失敗";
public static final String EDIT_CHECKGROUP_SUCCESS = "編輯檢查組成功";
public static final String PIC_UPLOAD_SUCCESS = "圖片上傳成功";
public static final String PIC_UPLOAD_FAIL = "圖片上傳失敗";
public static final String ADD_SETMEAL_FAIL = "新增套餐失敗";
public static final String ADD_SETMEAL_SUCCESS = "新增套餐成功";
public static final String IMPORT_ORDERSETTING_FAIL = "批量導入預約設置數據失敗";
public static final String IMPORT_ORDERSETTING_SUCCESS = "批量導入預約設置數據成功";
public static final String GET_ORDERSETTING_SUCCESS = "獲取預約設置數據成功";
public static final String GET_ORDERSETTING_FAIL = "獲取預約設置數據失敗";
public static final String ORDERSETTING_SUCCESS = "預約設置成功";
public static final String ORDERSETTING_FAIL = "預約設置失敗";
public static final String ADD_MEMBER_FAIL = "新增會員失敗";
public static final String ADD_MEMBER_SUCCESS = "新增會員成功";
public static final String DELETE_MEMBER_FAIL = "刪除會員失敗";
public static final String DELETE_MEMBER_SUCCESS = "刪除會員成功";
public static final String EDIT_MEMBER_FAIL = "編輯會員失敗";
public static final String EDIT_MEMBER_SUCCESS = "編輯會員成功";
public static final String TELEPHONE_VALIDATECODE_NOTNULL = "手機號和驗證碼都不能為空";
public static final String LOGIN_SUCCESS = "登錄成功";
public static final String VALIDATECODE_ERROR = "驗證碼輸入錯誤";
public static final String QUERY_ORDER_SUCCESS = "查詢預約信息成功";
public static final String QUERY_ORDER_FAIL = "查詢預約信息失敗";
public static final String QUERY_SETMEALLIST_SUCCESS = "查詢套餐列表數據成功";
public static final String QUERY_SETMEALLIST_FAIL = "查詢套餐列表數據失敗";
public static final String QUERY_SETMEAL_SUCCESS = "查詢套餐數據成功";
public static final String QUERY_SETMEAL_FAIL = "查詢套餐數據失敗";
public static final String SEND_VALIDATECODE_FAIL = "驗證碼發送失敗";
public static final String SEND_VALIDATECODE_SUCCESS = "驗證碼發送成功";
public static final String SELECTED_DATE_CANNOT_ORDER = "所選日期不能進行體檢預約";
public static final String ORDER_FULL = "預約已滿";
public static final String HAS_ORDERED = "已經完成預約,不能重復預約";
public static final String ORDER_SUCCESS = "預約成功";
public static final String GET_USERNAME_SUCCESS = "獲取當前登錄用戶名稱成功";
public static final String GET_USERNAME_FAIL = "獲取當前登錄用戶名稱失敗";
public static final String GET_MENU_SUCCESS = "獲取當前登錄用戶菜單成功";
public static final String GET_MENU_FAIL = "獲取當前登錄用戶菜單失敗";
public static final String GET_MEMBER_NUMBER_REPORT_SUCCESS = "獲取會員統計數據成功";
public static final String GET_MEMBER_NUMBER_REPORT_FAIL = "獲取會員統計數據失敗";
public static final String GET_SETMEAL_COUNT_REPORT_SUCCESS = "獲取套餐統計數據成功";
public static final String GET_SETMEAL_COUNT_REPORT_FAIL = "獲取套餐統計數據失敗";
public static final String GET_BUSINESS_REPORT_SUCCESS = "獲取運營統計數據成功";
public static final String GET_BUSINESS_REPORT_FAIL = "獲取運營統計數據失敗";
public static final String GET_SETMEAL_LIST_SUCCESS = "查詢套餐列表數據成功";
public static final String GET_SETMEAL_LIST_FAIL = "查詢套餐列表數據失敗";
}
(2)返回結果Result和PageResult類,放到health_common工程中
package com.itheima.entity;
import java.io.Serializable;
/**
* 封裝返回結果
*/
public class Result implements Serializable{
private boolean flag;//執行結果,true為執行成功 false為執行失敗
private String message;//返回提示信息,主要用於頁面提示信息
private Object data;//返回數據
public Result(boolean flag, String message) {
super();
this.flag = flag;
this.message = message;
}
public Result(boolean flag, String message, Object data) {
this.flag = flag;
this.message = message;
this.data = data;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
}
package com.itheima.entity;
import java.io.Serializable;
import java.util.List;
/**
* 分頁結果封裝對象
*/
public class PageResult implements Serializable{
private Long total;//總記錄數
private List rows;//當前頁結果
public PageResult(Long total, List rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
}
(3)封裝查詢條件的QueryPageBean類,放到health_common工程中
package com.itheima.entity;
import java.io.Serializable;
/**
* 封裝查詢條件
*/
public class QueryPageBean implements Serializable{
private Integer currentPage;//頁碼
private Integer pageSize;//每頁記錄數
private String queryString;//查詢條件
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
public String getQueryString() {
return queryString;
}
public void setQueryString(String queryString) {
this.queryString = queryString;
}
}
(4)html、js、css、圖片等靜態資源,放到health_backend工程中
注意:后續隨着項目開發還會陸續導入其他一些公共資源。
3. 新增檢查項
3.1 完善頁面
檢查項管理頁面對應的是checkitem.html頁面,根據產品設計的原型已經完成了頁面基本結構的編寫,現在需要完善頁面動態效果。
3.1.1 彈出新增窗口
頁面中已經提供了新增窗口,只是處於隱藏狀態。只需要將控制展示狀態的屬性dialogFormVisible改為true就可以顯示出新增窗口。
新建按鈕綁定的方法為handleCreate,所以在handleCreate方法中修改dialogFormVisible屬性的值為true即可。同時為了增加用戶體驗度,需要每次點擊新建按鈕時清空表單輸入項。
// 重置表單
resetForm() {
this.formData = {};
},
// 彈出添加窗口
handleCreate() {
this.resetForm();
this.dialogFormVisible = true;
}
3.1.2 輸入校驗
rules: {//校驗規則
code: [{ required: true, message: '項目編碼為必填項', trigger: 'blur' }],
name: [{ required: true, message: '項目名稱為必填項', trigger: 'blur' }]
}
3.1.3 提交表單數據
點擊新增窗口中的確定按鈕時,觸發handleAdd方法,所以需要在handleAdd方法中進行完善。
handleAdd () {
//校驗表單輸入項是否合法
this.$refs['dataAddForm'].validate((valid) => {
if (valid) {
//表單數據校驗通過,發送ajax請求將表單數據提交到后台
axios.post("/checkitem/add.do",this.formData).then((response)=> {
//隱藏新增窗口
this.dialogFormVisible = false;
//判斷后台返回的flag值,true表示添加操作成功,false為添加操作失敗
if(response.data.flag){
this.$message({
message: response.data.message,
type: 'success'
});
}else{
this.$message.error(response.data.message);
}
}).finally(()=> {
this.findPage();
});
} else {
this.$message.error("表單數據校驗失敗");
return false;
}
});
}
3.2 后台代碼
3.2.1 Controller
在health_backend工程中創建CheckItemController
package com.itheima.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 體檢檢查項管理
*/
@RestController
@RequestMapping("/checkitem")
public class CheckItemController {
@Reference
private CheckItemService checkItemService;
//新增
@RequestMapping("/add")
public Result add(@RequestBody CheckItem checkItem){
try {
checkItemService.add(checkItem);
}catch (Exception e){
return new Result(false,MessageConstant.ADD_CHECKITEM_FAIL);
}
return new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
}
}
3.2.2 服務接口
在health_interface工程中創建CheckItemService接口
package com.itheima.service;
import com.itheima.pojo.CheckItem;
import java.util.List;
/**
* 檢查項服務接口
*/
public interface CheckItemService {
public void add(CheckItem checkItem);
}
3.2.3 服務實現類
在health_service_provider工程中創建CheckItemServiceImpl實現類
package com.itheima.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.CheckItemDao;
import com.itheima.pojo.CheckItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
/**
* 檢查項服務
*/
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {
@Autowired
private CheckItemDao checkItemDao;
//新增
public void add(CheckItem checkItem) {
checkItemDao.add(checkItem);
}
}
3.2.4 Dao接口
在health_service_provider工程中創建CheckItemDao接口,本項目是基於Mybatis的Mapper代理技術實現持久層操作,故只需要提供接口和Mapper映射文件,無須提供實現類
package com.itheima.dao;
import com.itheima.pojo.CheckItem;
/**
* 持久層Dao接口
*/
public interface CheckItemDao {
public void add(CheckItem checkItem);
}
3.2.5 Mapper映射文件
在health_service_provider工程中創建CheckItemDao.xml映射文件,需要和CheckItemDao接口在同一目錄下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.itheima.dao.CheckItemDao">
<!--新增-->
<insert id="add" parameterType="com.itheima.pojo.CheckItem">
insert into t_checkitem(code,name,sex,age,price,type,remark,attention)
values
(#{code},#{name},#{sex},#{age},#{price},#{type},#{remark},#{attention})
</insert>
</mapper>
4. 檢查項分頁
本項目所有分頁功能都是基於ajax的異步請求來完成的,請求參數和后台響應數據格式都使用json數據格式。
請求參數包括頁碼、每頁顯示記錄數、查詢條件。
請求參數的json格式為:{currentPage:1,pageSize:10,queryString:''itcast''}
后台響應數據包括總記錄數、當前頁需要展示的數據集合。
響應數據的json格式為:{total:1000,rows:[]}
如下圖:
4.1 完善頁面
4.1.1 定義分頁相關模型數據
pagination: {//分頁相關模型數據
currentPage: 1,//當前頁碼
pageSize:10,//每頁顯示的記錄數
total:0,//總記錄數
queryString:null//查詢條件
},
dataList: [],//當前頁要展示的分頁列表數據
4.1.2 定義分頁方法
在頁面中提供了findPage方法用於分頁查詢,為了能夠在checkitem.html頁面加載后直接可以展示分頁數據,可以在VUE提供的鈎子函數created中調用findPage方法
//鈎子函數,VUE對象初始化完成后自動執行
created() {
this.findPage();
}
//分頁查詢
findPage() {
//分頁參數
var param = {
currentPage:this.pagination.currentPage,//頁碼
pageSize:this.pagination.pageSize,//每頁顯示的記錄數
queryString:this.pagination.queryString//查詢條件
};
//請求后台
axios.post("/checkitem/findPage.do",param).then((response)=> {
//為模型數據賦值,基於VUE的雙向綁定展示到頁面
this.dataList = response.data.rows;
this.pagination.total = response.data.total;
});
}
4.1.3 完善分頁方法執行時機
除了在created鈎子函數中調用findPage方法查詢分頁數據之外,當用戶點擊查詢按鈕或者點擊分頁條中的頁碼時也需要調用findPage方法重新發起查詢請求。
為查詢按鈕綁定單擊事件,調用findPage方法
<el-button @click="findPage()" class="dalfBut">查詢</el-button>
為分頁條組件綁定current-change事件,此事件是分頁條組件自己定義的事件,當頁碼改變時觸發,對應的處理函數為handleCurrentChange
<el-pagination
class="pagiantion"
@current-change="handleCurrentChange"
:current-page="pagination.currentPage"
:page-size="pagination.pageSize"
layout="total, prev, pager, next, jumper"
:total="pagination.total">
</el-pagination>
定義handleCurrentChange方法
//切換頁碼
handleCurrentChange(currentPage) {
//currentPage為切換后的頁碼
this.pagination.currentPage = currentPage;
this.findPage();
}
4.2 后台代碼
4.2.1 Controller
在CheckItemController中增加分頁查詢方法
//分頁查詢
@RequestMapping("/findPage")
public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
PageResult pageResult = checkItemService.pageQuery(
queryPageBean.getCurrentPage(),
queryPageBean.getPageSize(),
queryPageBean.getQueryString());
return pageResult;
}
4.2.2 服務接口
在CheckItemService服務接口中擴展分頁查詢方法
public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString);
4.2.3 服務實現類
在CheckItemServiceImpl服務實現類中實現分頁查詢方法,基於Mybatis分頁助手插件實現分頁
public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
PageHelper.startPage(currentPage,pageSize);
Page<CheckItem> page = checkItemDao.selectByCondition(queryString);
return new PageResult(page.getTotal(),page.getResult());
}
4.2.4 Dao接口
在CheckItemDao接口中擴展分頁查詢方法
public Page<CheckItem> selectByCondition(String queryString);
4.2.5 Mapper映射文件
在CheckItemDao.xml文件中增加SQL定義
<select id="selectByCondition" parameterType="string"
resultType="com.itheima.pojo.CheckItem">
select * from t_checkitem
<if test="value != null and value.length > 0">
where code = #{value} or name = #{value}
</if>
</select>
5. 刪除檢查項
5.1 完善頁面
為了防止用戶誤操作,點擊刪除按鈕時需要彈出確認刪除的提示,用戶點擊取消則不做任何操作,用戶點擊確定按鈕再提交刪除請求。
5.1.1 綁定單擊事件
需要為刪除按鈕綁定單擊事件,並且將當前行數據作為參數傳遞給處理函數
<el-button size="mini" type="danger" @click="handleDelete(scope.row)">刪除</el-button>
// 刪除
handleDelete(row) {
alert(row.id);
}
5.1.2 彈出確認操作提示
用戶點擊刪除按鈕會執行handleDelete方法,此處需要完善handleDelete方法,彈出確認提示信息。ElementUI提供了$confirm方法來實現確認提示信息彈框效果
// 刪除
handleDelete(row) {
//alert(row.id);
this.$confirm("確認刪除當前選中記錄嗎?","提示",{type:'warning'}).then(()=>{
//點擊確定按鈕時只需此處代碼
alert('用戶點擊的是確定按鈕');
});
}
5.1.3 發送請求
如果用戶點擊確定按鈕就需要發送ajax請求,並且將當前檢查項的id作為參數提交到后台進行刪除操作
// 刪除
handleDelete(row) {
//alert(row.id);
this.$confirm("確認刪除嗎?","提示",{type:'warning'}).then(()=>{
//點擊確定按鈕時只需此處代碼
//alert('用戶點擊的是確定按鈕');
axios.get("/checkitem/delete.do?id=" + row.id).then((res)=> {
if(!res.data.flag){
//刪除失敗
this.$message.error(res.data.message);
}else{
//刪除成功
this.$message({
message: res.data.message,
type: 'success'
});
//調用分頁,獲取最新分頁數據
this.findPage();
}
});
});
}
5.2 后台代碼
5.2.1 Controller
在CheckItemController中增加刪除方法
//刪除
@RequestMapping("/delete")
public Result delete(Integer id){
try {
checkItemService.delete(id);
}catch (RuntimeException e){
return new Result(false,e.getMessage());
}catch (Exception e){
return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
}
return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
}
5.2.2 服務接口
在CheckItemService服務接口中擴展刪除方法
public void delete(Integer id);
5.2.3 服務實現類
注意:不能直接刪除,需要判斷當前檢查項是否和檢查組關聯,如果已經和檢查組進行了關聯則不允許刪除
//刪除
public void delete(Integer id) throws RuntimeException{
//查詢當前檢查項是否和檢查組關聯
long count = checkItemDao.findCountByCheckItemId(id);
if(count > 0){
//當前檢查項被引用,不能刪除
throw new RuntimeException("當前檢查項被引用,不能刪除");
}
checkItemDao.deleteById(id);
}
5.2.4 Dao接口
在CheckItemDao接口中擴展方法findCountByCheckItemId和deleteById
public void deleteById(Integer id);public long findCountByCheckItemId(Integer checkItemId);
5.2.5 Mapper映射文件
在CheckItemDao.xml中擴展SQL語句
<!--刪除-->
<delete id="deleteById" parameterType="int">
delete from t_checkitem where id = #{id}
</delete>
<!--根據檢查項id查詢中間關系表-->
<select id="findCountByCheckItemId" resultType="long" parameterType="int">
select count(*) from t_checkgroup_checkitem where checkitem_id = #{checkitem_id}
</select>
6. 編輯檢查項
6.1 完善頁面
用戶點擊編輯按鈕時,需要彈出編輯窗口並且將當前記錄的數據進行回顯,用戶修改完成后點擊確定按鈕將修改后的數據提交到后台進行數據庫操作。
6.1.1 綁定單擊事件
需要為編輯按鈕綁定單擊事件,並且將當前行數據作為參數傳遞給處理函數
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">編輯</el-button>
handleUpdate(row) {
alert(row);
}
6.1.2 彈出編輯窗口回顯數據
當前頁面中的編輯窗口已經提供好了,默認處於隱藏狀態。在handleUpdate方法中需要將編輯窗口展示出來,並且需要發送ajax請求查詢當前檢查項數據用於回顯
// 彈出編輯窗口
handleUpdate(row) {
//發送請求獲取檢查項信息
axios.get("/checkitem/findById.do?id=" + row.id).then((res)=>{
if(res.data.flag){
//設置編輯窗口屬性,dialogFormVisible4Edit為true表示顯示
this.dialogFormVisible4Edit = true;
//為模型數據設置值,基於VUE雙向數據綁定回顯到頁面
this.formData = res.data.data;
}else{
this.$message.error("獲取數據失敗,請刷新當前頁面");
}
});
}
6.1.3 發送請求
在編輯窗口中修改完成后,點擊確定按鈕需要提交請求,所以需要為確定按鈕綁定事件並提供處理函數handleEdit
<el-button type="primary" @click="handleEdit()">確定</el-button>
//編輯
handleEdit() {
//表單校驗
this.$refs['dataEditForm'].validate((valid)=>{
if(valid){
//表單校驗通過,發送請求
axios.post("/checkitem/edit.do",this.formData).then((response)=> {
//隱藏編輯窗口
this.dialogFormVisible4Edit = false;
if(response.data.flag){
//編輯成功,彈出成功提示信息
this.$message({
message: response.data.message,
type: 'success'
});
}else{
//編輯失敗,彈出錯誤提示信息
this.$message.error(response.data.message);
}
}).finally(()=> {
//重新發送請求查詢分頁數據
this.findPage();
});
}else{
//表單校驗失敗
this.$message.error("表單數據校驗失敗");
return false;
}
});
}
6.2 后台代碼
6.2.1 Controller
在CheckItemController中增加編輯方法
//編輯
@RequestMapping("/edit")
public Result edit(@RequestBody CheckItem checkItem){
try {
checkItemService.edit(checkItem);
}catch (Exception e){
return new Result(false,MessageConstant.EDIT_CHECKITEM_FAIL);
}
return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
}
@RequestMapping("/findById")
public Result findById(Integer id){
try{
CheckItem checkItem = checkItemService.findById(id);
return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);
}catch (Exception e){
e.printStackTrace();
//服務調用失敗
return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
}
}
6.2.2 服務接口
在CheckItemService服務接口中擴展編輯方法
public void edit(CheckItem checkItem);
public CheckItem findById(Integer id);
6.2.3 服務實現類
在CheckItemServiceImpl實現類中實現編輯方法
//編輯
public void edit(CheckItem checkItem) {
checkItemDao.edit(checkItem);
}
public CheckItem findById(Integer id) {
return checkItemDao.findById(id);
}
6.2.4 Dao接口
在CheckItemDao接口中擴展edit方法
public void edit(CheckItem checkItem);
public CheckItem findById(Integer id);
6.2.5 Mapper映射文件
在CheckItemDao.xml中擴展SQL語句
<!--編輯-->
<update id="edit" parameterType="com.itheima.pojo.CheckItem">
update t_checkitem
<set>
<if test="name != null">
name = #{name},
</if>
<if test="sex != null">
sex = #{sex},
</if>
<if test="code != null">
code = #{code},
</if>
<if test="age != null">
age = #{age},
</if>
<if test="price != null">
price = #{price},
</if>
<if test="type != null">
type = #{type},
</if>
<if test="attention != null">
attention = #{attention},
</if>
<if test="remark != null">
remark = #{remark},
</if>
</set>
where id = #{id}
</update>
<select id="findById" parameterType="int" resultType="com.itheima.pojo.CheckItem">
select * from t_checkitem where id = #{id}
</select>