1. 程式人生 > >控制器返回值型別設定

控制器返回值型別設定

 一、返回整型

@Controller
public class UserC {
	@Autowired
	private UserBizImpl impl;
	@ResponseBody
	@RequestMapping("/lixiang")
	public Integer  getAll(Integer id,String name,String password,Integer fid,Integer index){
		pageUtil<User> page= new pageUtil<User>();
		if(index!=null&&!index.equals("")){
			page.setIndex(index);
		}
		impl.getAll(id, name, password, fid, page);
		return page.getSize();
		
	}

}

以上程式碼返回int型別。注意返回值型別需要與資料返回值型別設定為一致。

如上方Integer 型別設定,size也為Integer型別。

二、返回集合

@Controller
public class UserC {
	@Autowired
	private UserBizImpl impl;
	@ResponseBody
	@RequestMapping("/lixiang")
	public List<User> getAll(Integer id,String name,String password,Integer fid,Integer index){
		pageUtil<User> page= new pageUtil<User>();
		if(index!=null&&!index.equals("")){
			page.setIndex(index);
		}
		impl.getAll(id, name, password, fid, page);
		return page.getPage();
		
	}

}

以上程式碼返回list集合型別。注意返回值型別需要與資料返回值型別設定為一致。

如上方list型別設定。所以實體類中需要對應的page集合。

例如: