ssm框架使用resultful_ssm框架前后端数据交互完整示例

packagecom.dengfeng.house.controller;importjava.text.ParseException;importjava.util.Date;importjava.util.List;importjavax.annotation.Resource;importjavax.servlet.http.HttpSession;importorg.springframework.stereotype.Controller;importorg.springframework.ui.Model;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RequestParam;importorg.springframework.web.bind.annotation.ResponseBody;importcom.github.pagehelper.PageHelper;importcom.github.pagehelper.PageInfo;importcom.dengfeng.house.pojo.District;importcom.dengfeng.house.pojo.House;importcom.dengfeng.house.pojo.HouseQuery;importcom.dengfeng.house.pojo.Street;importcom.dengfeng.house.pojo.Type;importcom.dengfeng.house.pojo.User;importcom.dengfeng.house.service.IDistrictService;importcom.dengfeng.house.service.IHouseService;importcom.dengfeng.house.service.IStreetService;importcom.dengfeng.house.service.ITypeService;

@Controller

@RequestMapping("/house")public classHouseController {

@ResourceprivateIHouseService houseService;

@ResourceprivateITypeService typeService;

@ResourceprivateIDistrictService districtService;

@ResourceprivateIStreetService streetService;//manage页面全查

@RequestMapping("/findAll")

@ResponseBodypublic PageInfo findAll(@RequestParam(defaultValue="1")intpageIndex){

PageHelper.startPage(pageIndex,3);

List housList =houseService.selectHouse();

PageInfo pageInfo=new PageInfo(housList);returnpageInfo;

}//修改渲染

@RequestMapping("/update/{id}")public String update(Model model,@PathVariable intid){

List typeList =typeService.findAllType();

List districtList =districtService.findAllDistrict();

List streetList=streetService.findAllStreet();

House house=houseService.findHouseById(id);

model.addAttribute("house", house);

model.addAttribute("typeList", typeList);

model.addAttribute("districtList", districtList);

model.addAttribute("streetList", streetList);return "/page/update";

}//保存修改

@RequestMapping("/updateSave")publicString update(House house){

houseService.alterHouse(house);return "redirect:/page/manage.jsp";

}//渲染增加,下拉框推荐用ajxj做,,=所有这个方法没什么用

@RequestMapping("/add")publicString add(Model model){

List typeList =typeService.findAllType();/*List districtList = districtService.findAllDistrict();

List streetList= streetService.findAllStreet();*/model.addAttribute("typeList", typeList);/*model.addAttribute("districtList", districtList);

model.addAttribute("streetList", streetList);*/

return "/page/add";

}//真正保存增加的方法

@RequestMapping("/addSave")publicString addSave(House house,HttpSession session){

houseService.insertHouse(house);return "redirect:/page/manage.jsp";

}/*house_list.jsp查询。*/@RequestMapping("/find")

@ResponseBodypublic Listfind(HouseQuery houseQuery,String money,String size){//如果是选中状态

if(money!=null&&!money.equals("")){

String[] moneyArray=money.split("-");

houseQuery.setMinPrice(Integer.parseInt(moneyArray[0]));

houseQuery.setMaxPrice(Integer.parseInt(moneyArray[1]));

}if(size!=null&&!size.equals("")){

String[] sizeArray=size.split("-");

houseQuery.setMinFloorAge(Integer.parseInt(sizeArray[0]));

houseQuery.setMaxFloorAge(Integer.parseInt(sizeArray[1]));

}

List list =houseService.find(houseQuery);returnlist;

}//推荐,多条件模糊查询/*@RequestMapping("/findAllHouseList")

@ResponseBody

public PageInfo findAll(HttpSession session,@RequestParam(defaultValue="1")Integer pageIndex,

@RequestParam(defaultValue="")String title,

@RequestParam(defaultValue="")String price,

@RequestParam(defaultValue="")Integer typeId,

@RequestParam(defaultValue="0")String floorage,Date beginTime,Date endTime) throws ParseException{

User user=(User)session.getAttribute("userSession");

String[] prices = price.split("-");

String[] floorages = floorage.split("-");

if(user!=null) {

PageHelper.startPage(pageIndex,2);

House house =new House ();

house.setTitle(title);

house.setMinPrice(Integer.parseInt(prices[0]));

house.setMaxPrice(Integer.parseInt(prices[1]));

house.setTypeId(typeId);

house.setMinFloorage(Integer.parseInt(floorages[0]));

house.setMaxFloorage(Integer.parseInt(floorages[1]));

if(beginTime!=null && endTime!=null){

house.setBeginTime(beginTime);

house.setEndTime(endTime);

}else if(beginTime!=null){

house.setBeginTime(beginTime);

}else if(endTime!=null){

house.setEndTime(endTime);

}

List list = houseService.findByCondition(house);

PageInfo pageInfo=new PageInfo(list);

return pageInfo;

}

return new PageInfo();

}*/

//删除房子

@RequestMapping("/deleteById")

@ResponseBodypublic String delete(intid){

houseService.deletehouse(id);return "删除成功";

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值