zoukankan      html  css  js  c++  java
  • Java高级架构师(一)第13节:Spring MVC实现Web层开发

    package com.sishuok.architecture1.customermgr.web;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    
    import com.sishuok.architecture1.customermgr.service.ICustomerService;
    import com.sishuok.architecture1.customermgr.vo.CustomerModel;
    import com.sishuok.architecture1.customermgr.vo.CustomerQueryModel;
    import com.sishuok.pageutil.Page;
    import com.sishuok.util.format.DateFormatHelper;
    import com.sishuok.util.json.JsonHelper;
    
    @Controller
    @RequestMapping(value="/customer")
    public class CustomerController {
    	@Autowired
    	private ICustomerService ics = null;
    	
    	@RequestMapping(value="toAdd",method=RequestMethod.GET)
    	public String toAdd(){
    		
    		return "customer/add";
    	}
    	@RequestMapping(value="add",method=RequestMethod.POST)
    	public String add(@ModelAttribute("cm") CustomerModel cm){
    		cm.setRegisterTime(DateFormatHelper.long2str(System.currentTimeMillis()));
    		ics.create(cm);
    		return "customer/success";
    	}
    	@RequestMapping(value="toUpdate/{customerUuid}",method=RequestMethod.GET)
    	public String toUpdate(Model model,@PathVariable("customerUuid") int customerUuid){
    		CustomerModel cm = ics.getByUuid(customerUuid);
    		model.addAttribute("cm", cm);
    		return "customer/update";
    	}
    	@RequestMapping(value="update",method=RequestMethod.POST)
    	public String post(@ModelAttribute("cm") CustomerModel cm){
    		ics.update(cm);
    		return "customer/success";
    	}
    	@RequestMapping(value="toDelete/{customerUuid}",method=RequestMethod.GET)
    	public String toDelete(Model model,@PathVariable("customerUuid") int customerUuid){
    		CustomerModel cm = ics.getByUuid(customerUuid);
    		model.addAttribute("cm", cm);
    		return "customer/delete";
    	}
    	@RequestMapping(value="delete",method=RequestMethod.POST)
    	public String post(@RequestParam("uuid") int customerUuid){
    		ics.delete(customerUuid);
    		return "customer/success";
    	}
    	@RequestMapping(value="toList",method=RequestMethod.GET)
    	public String toList(@ModelAttribute("wm")CustomerWebModel wm,Model model){
    		CustomerQueryModel cqm = null;
    		if(wm.getQueryJsonStr()==null || wm.getQueryJsonStr().trim().length()==0){
    			cqm =  new CustomerQueryModel();
    		}else{
    			cqm = (CustomerQueryModel)JsonHelper.str2Object(wm.getQueryJsonStr(), CustomerQueryModel.class);
    		}
    		
    		cqm.getPage().setNowPage(wm.getNowPage());
    		if(wm.getPageShow() > 0){
    			cqm.getPage().setPageShow(wm.getPageShow());
    		}
    		
    		Page dbPage = ics.getByConditionPage(cqm);
    		
    		//
    		model.addAttribute("wm", wm);
    		model.addAttribute("page", dbPage);
    				
    		return "customer/list";
    	}
    	@RequestMapping(value="toQuery",method=RequestMethod.GET)
    	public String toQuery(){
    		return "customer/query";
    	}	
    }
    

      

  • 相关阅读:
    FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
    如何去设计一个自适应的网页设计或HTMl5
    教育行业SaaS选型 需要注意的三点问题
    SaaS系列介绍之十五: SaaS知识重用
    SaaS系列介绍之十四: SaaS软件开发分析
    SaaS系列介绍之十三: SaaS系统体系架构
    SaaS系列介绍之十二: SaaS产品的研发模式
    个人总结
    用例图设计
    第二次结对作业
  • 原文地址:https://www.cnblogs.com/sunrunzhi/p/10110587.html
Copyright © 2011-2022 走看看