`
xiangkun
  • 浏览: 100022 次
  • 性别: Icon_minigender_1
  • 来自: 马尔代夫
社区版块
存档分类
最新评论

Spring rest 小试牛刀

 
阅读更多

最近用Spring rest 做了个小站。其中包含了部分CMS功能。

网站地址:www.jsrzx.com  (驾驶人在线)

 

部分代码贴在下面:

 

/**
	 * 转换日期绑定
	 * @param request
	 * @param binder
	 * @throws Exception
	 */
	@InitBinder
	protected void convertDateFormat(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { 
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
		dateFormat.setLenient(false); 
		CustomDateEditor editor = new CustomDateEditor(dateFormat, false);
		binder.registerCustomEditor(Date.class, editor);
	}
	
	
	/**
	 * 页面跳转
	 * @param res
	 */
	protected void sendRedirect(HttpServletResponse res,String location){
		try {
			res.sendRedirect(location);
		} catch (IOException e) {
			System.out.println("页面跳转出错!" + e.getMessage());
		}
	}
	
	/**
	 * 获取请求来路
	 * @param req
	 * @return
	 */
	protected String getRequestURL(HttpServletRequest req){
		String fromUrl = StringUtils.isNotEmpty(req.getHeader("Referer")) ? req.getHeader("Referer") : req.getParameter("returnUrl");
		if(StringUtils.isNull(fromUrl) || fromUrl.indexOf(Constants.DOMAIN) == -1){
			fromUrl = Constants.DOMAIN;
		}
		return fromUrl;
	}
	
	/**
	 * 获取项目上下文
	 * @param req
	 * @return
	 */
	protected String getContext(HttpServletRequest req){
		String context = req.getContextPath();
		if(!StringUtils.isNotEmpty(context))
			context = Constants.DOMAIN;
		return context;
	}
	

 

 有一起探讨的,欢迎留言!!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics