欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

传智健康项目讲义第五章 四

程序员文章站 2022-05-30 17:45:18
...

4.2 后台代码 
4.2.1 Controller 
OrderSettingController中提供getOrderSettingByMonth方法,根据月份查询预约设置信息

/**
* 根据日期查询预约设置数据(获取指定日期所在月份的预约设置数据)
* @param date
* @return
*/
@RequestMapping("/getOrderSettingByMonth")
public Result getOrderSettingByMonth(String date){//参数格式为:2019‐03
try{
List<Map> list = orderSettingService.getOrderSettingByMonth(date);
//获取预约设置数据成功
return new
Result(true,MessageConstant.GET_ORDERSETTING_SUCCESS,list);
}catch (Exception e){
e.printStackTrace();
//获取预约设置数据失败
return new Result(false,MessageConstant.GET_ORDERSETTING_FAIL);
}
}

4.2.2 服务接口
OrderSettingService服务接口中扩展方法getOrderSettingByMonth 
 

public List<Map> getOrderSettingByMonth(String date);//参数格式为:2019‐03

4.2.3 服务实现类 
OrderSettingServiceImpl服务实现类中实现方法getOrderSettingByMonth

//根据日期查询预约设置数据
public List<Map> getOrderSettingByMonth(String date) {//2019‐3
String dateBegin = date + "‐1";//2019‐3‐1
String dateEnd = date + "‐31";//2019‐3‐31
Map map = new HashMap();
map.put("dateBegin",dateBegin);
map.put("dateEnd",dateEnd);
List<OrderSetting> list = orderSettingDao.getOrderSettingByMonth(map);
List<Map> data = new ArrayList<>();
for (OrderSetting orderSetting : list) {
Map orderSettingMap = new HashMap();
orderSettingMap.put("date",orderSetting.getOrderDate().getDate());//
获得日期(几号)
orderSettingMap.put("number",orderSetting.getNumber());//可预约人数
orderSettingMap.put("reservations",orderSetting.getReservations());//
已预约人数
data.add(orderSettingMap);
}
return data;
}

4.2.4 Dao接口 
OrderSettingDao接口中扩展方法getOrderSettingByMonth
 

public List<OrderSetting> getOrderSettingByMonth(Map date);

4.2.5 Mapper映射文件 
OrderSettingDao.xml文件中扩展SQL

<!‐‐根据月份查询预约设置信息‐‐>
<select id="getOrderSettingByMonth"
parameterType="hashmap"
resultType="com.itheima.pojo.OrderSetting">
select * from t_ordersetting where orderDate between #{dateBegin} and #
{dateEnd}
</select>