Controller层方法错误

原创
2015/07/15 18:55
阅读数 417
package com.cisetech.web.controller.savecontroller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cisetech.result.BaseResult;
import com.cisetech.result.SearchOrderResult;
import com.cisetech.service.openrecordservice.WechatSaveUpRecordService;
import com.cisetech.service.saveoneservice.SaveExplainService;
import com.cisetech.service.saveoneservice.SaveOnePeiceService;
import com.cisetech.util.JsonUtils;
import com.cisetech.util.PropertiesLoader;
import com.cisetech.vo.saveonevo.WechatSaveUpRecordVo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;


/**
 * 用于测试前后台交换和操作数据库
 * @author yq
 *
 */
@Controller
@RequestMapping("/totest")
public class TestController {
	
private final static Logger log = LoggerFactory.getLogger(TestController.class);
	
	@Autowired
	private SaveOnePeiceService saveOnePeiceService;
	
	@Autowired
	private SaveExplainService saveExplainService;
	
	
	/**
	 * 测试字符串返回通过
	 * @return
	 */
	@RequestMapping("/totest")
	@ResponseBody
	public String getOnePeiece(){
		return "you are very goods";
	}
	
	/**
	 * 测试页面通过
	 * @return
	 */
	@RequestMapping("/firstPage")
	public String testgetFirstPage(){
		System.out.println("===into getFirstPage====");
		return "login"; 
	}
	
	/**
	 * 测试后端传json到前端通过
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/jsonToPage")
	@ResponseBody
	public String testJsontoPage() throws Exception{
		BaseResult result = new BaseResult();
		result.setCode(result.SUCCESS);
		result.setMessage("您成功了");
		result.setDate("123455");
		return JsonUtils.obj2Json(result); 
	}
	
	
	
	/**
	 * 测试查找数据库通过
	 * @return
	 */
	@RequestMapping("/findAll")
	@ResponseBody
	public String testSelect(){
		SearchOrderResult result  = saveOnePeiceService.getOrderByOrderNo("11");
//		List<WechatSaveUpRecordVo> volist = saveOnePeiceService.findAll();
//		System.out.println("volist:"+volist);
		return new Gson().toJson(result);
	}
	
	@RequestMapping("/test")
	public ModelAndView select(){
		int i=0;
		ModelAndView mv = new ModelAndView();
		WechatSaveUpRecordVo s=new WechatSaveUpRecordVo();
		String currentSchema = (new PropertiesLoader()).getProperty("currentSchema");
		System.out.println(currentSchema);
		s.setId(10000002);
		s.setCurrentSchema(currentSchema);
		
		s=saveOnePeiceService.test(s);
		//s=saveOnePeiceService.test1(currentSchema, "1");
		
		System.out.println(s.getId()+"存一笔记录表id");
		System.out.println(s.getSaveOpenId()+"存钱人openid");
		System.out.println(s.getSaveMoney()+"存钱金额");
		System.out.println(s.getSaveDate()+"存钱时间");
		System.out.println(s.getSaveState()+"存钱状态");
		System.out.println(s.getOrderNo()+"保单号");
		System.out.println(s.getInsuredId()+"被保人ID");
		System.out.println(s.getSaveReasonId()+"存钱事由id");
		System.out.println(s.getSelfSaveReason()+"存钱说明");
		System.out.println(s.getPayNo()+"PAY_NO支付号");
		
		WechatSaveUpRecordVo vo=new WechatSaveUpRecordVo();
		
//		vo.setCurrentSchema(currentSchema);
//		vo.setInsuredId("12");
//		vo.setOrderNo("12");
//		vo.setSaveDate(new Date(System.currentTimeMillis()));
//		//vo.setSaveOpenId("12345678");
//		vo.setSaveReasonId("12");
//		vo.setSaveMoney("12");
//		vo.setSelfSaveReason("今天心情不错啊");
//		vo.setSaveState("1");
//		vo.setPayNo("1");
//		
//		// i=saveOnePeiceService.insertWechatSaveUpRecord(vo);
		
		vo.setId(s.getId());
		vo.setSaveMoney("100");
		i=saveOnePeiceService.updateWechatSaveUpRecordById(vo);
		System.out.println(i);
		mv.addObject("s", s);
		mv.setViewName("CeShi");
		return mv;
	}
	
	/**
	 * 测试插入数据
	 * @return 
	 */
	@RequestMapping("/testInsert")
	@ResponseBody
	public String totestInsert(){
		log.info("===into test====");
		WechatSaveUpRecordVo vo = new WechatSaveUpRecordVo();
		BaseResult result = new BaseResult();
		vo.setInsuredId(10000000);
		vo.setOrderNo("3");
		vo.setSaveDate(new Date(System.currentTimeMillis()));
		vo.setSaveOpenId("123");
		vo.setSaveReasonId("1");
		vo.setSaveMoney("80");
		vo.setSelfSaveReason("今天心情不错啊");
		vo.setSaveState("1");
		System.out.println("===the saveUpRecordMapper:"+vo); 
		result = saveOnePeiceService.doSaveOne(vo, "1","心情不错"); 
		System.out.println("the result:"+result); 
		return new GsonBuilder().create().toJson(result); 
	}
	
	@RequestMapping("/getInsuredId")
	@ResponseBody
	public String getInsuredId(){
		String orderNo = "11";
		Integer id = saveOnePeiceService.getInsuredId(orderNo);
		return new Gson().toJson(id);
	}
	
	@RequestMapping("/test")
	public ModelAndView select1(){
		int i=0;
		ModelAndView mv = new ModelAndView();
		WechatSaveUpRecordVo s=new WechatSaveUpRecordVo();
		String currentSchema = (new PropertiesLoader()).getProperty("currentSchema");
		System.out.println(currentSchema);
		
		//select已通
//		s.setId(10000002);
//		s.setCurrentSchema(currentSchema);
//		s=saveOnePeiceService.test(s);
//		
//		System.out.println(s.getId()+"存一笔记录表id");
//		System.out.println(s.getSaveOpenId()+"存钱人openid");
//		System.out.println(s.getSaveMoney()+"存钱金额");
//		System.out.println(s.getSaveDate()+"存钱时间");
//		System.out.println(s.getSaveState()+"存钱状态");
//		System.out.println(s.getOrderNo()+"保单号");
//		System.out.println(s.getInsuredId()+"被保人ID");
//		System.out.println(s.getSaveReasonId()+"存钱事由id");
//		System.out.println(s.getSelfSaveReason()+"存钱说明");
//		System.out.println(s.getPayNo()+"PAY_NO支付号");
		
		WechatSaveUpRecordVo vo=new WechatSaveUpRecordVo();
		
		//insert已通
		vo.setCurrentSchema(currentSchema);
		vo.setInsuredId(12);
		vo.setOrderNo("12");
//		vo.setSaveDate(new Date(System.currentTimeMillis()));
//		vo.setSaveOpenId("12345678");
//		vo.setSaveReasonId("12");
//		vo.setSaveMoney("12");
		//vo.setSelfSaveReason("今天心情不错啊");
		vo.setSaveState("1");
		vo.setPayNo("1");
		//i=saveOnePeiceService.insertWechatSaveUpRecord(vo);
		i=saveOnePeiceService.insertSelective(vo);
		
		//update已通
		//s.setId(10000004);
//		s.setCurrentSchema(currentSchema);
//		s.setSaveMoney("200");
//		i=saveOnePeiceService.updateWechatSaveUpRecordById(s);
		
//		WechatCommenReasonVo crVo=new WechatCommenReasonVo();
//		crVo.setCurrentSchema(currentSchema);
//		crVo.setName("心情好");
//		i=saveExplainService.insert(crVo);
		System.out.println(i);
		mv.addObject("s", s);
		mv.setViewName("CeShi");
		return mv;
	}
	
	
	
}

上面的Contoller中的接口在tomcat启动的时候导致错误

2015-7-15 18:50:52 org.springframework.web.context.ContextLoader initWebApplicationContext

严重: Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'testController' bean method 

public org.springframework.web.servlet.ModelAndView com.cisetech.web.controller.savecontroller.TestController.select1()

to {[/totest/test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'testController' bean method

public org.springframework.web.servlet.ModelAndView com.cisetech.web.controller.savecontroller.TestController.select() mapped.

at org.

Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'testController' bean method 

public org.springframework.web.servlet.ModelAndView com.cisetech.web.controller.savecontroller.TestController.select1()

to {[/totest/test],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'testController' bean method

public org.springframework.web.servlet.ModelAndView com.cisetech.web.controller.savecontroller.TestController.select() mapped.



后把这个名字改了就好了

@RequestMapping("/test")

改成

@RequestMapping("/dotest")

可能是名字上不能有包含类名的接口方法名吧




展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部