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

 控制层导包

package com.dengfeng.house.controller;

import java.text.ParseException;

import java.util.Date;

import java.util.List;

import javax.annotation.Resource;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;

import com.github.pagehelper.PageInfo;

import com.dengfeng.house.pojo.District;

import com.dengfeng.house.pojo.House;

import com.dengfeng.house.pojo.HouseQuery;

import com.dengfeng.house.pojo.Street;

import com.dengfeng.house.pojo.Type;

import com.dengfeng.house.pojo.User;

import com.dengfeng.house.service.IDistrictService;

import com.dengfeng.house.service.IHouseService;

import com.dengfeng.house.service.IStreetService;

import com.dengfeng.house.service.ITypeService;

  springmvc控制层代码

    @Controller

    @RequestMapping("/house")

     public class HouseController {

        @Resource

        private IHouseService houseService;

        @Resource

             private ITypeService typeService;

             @Resource

             private IDistrictService districtService;

             @Resource

             private IStreetService streetService;

 

    //manage页面全查,返回值PageInfo是为了分页查询功能

    @RequestMapping("/findAll")

    @ResponseBody

    public PageInfo findAll(@RequestParam(defaultValue="1")int pageIndex){

        PageHelper.startPage(pageIndex, 3);

        List housList = houseService.selectHouse();

        PageInfo pageInfo=new PageInfo(housList);

      return pageInfo;

    }

 

    //修改渲染

    @RequestMapping("/update/{id}")

    public String update(Model model,@PathVariable int id){

        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")

      public String update(House house){

          houseService.alterHouse(house);

        return "redirect:/page/manage.jsp";

       }

 

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

      @RequestMapping("/add")

      public String 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")

      public String addSave(House house,HttpSession session){

          houseService.insertHouse(house);

        return "redirect:/page/manage.jsp";

      }

 

      /*house_list.jsp查询。/

      @RequestMapping("/find")

      @ResponseBody

      public List find(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);

        return list;

       }

 

      //推荐,动态查询

      /* @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")

      @ResponseBody

      public String delete(int id){

        houseService.deletehouse(id);

        return "删除成功";

      }

   }

 


 

  前端页面

<%@ page language="java" contentType="text/html;charset=UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%String path = request.getContextPath();

       String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

          int total = (Integer)request.getAttribute("total");

    %>

    

    用户管理

    <%--

    

     --%>

    

    

    

 

    

      

           

      

      

      

      

      

        

      

      

      

            

  • 共${param.totalCount }条记录   ${param.currentPageNo }/${param.totalPageCount }页
  •         

              首页

              上一页

            

            

              下一页

              最后一页

            

                

            

        

      

    

 


 JS代码

  

 

转载于:https://www.cnblogs.com/binghuaZhang/p/10809844.html

你可能感兴趣的:(javascript,xhtml,前端)