/** * Get a float parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static float getFloatParameter(ServletRequest request, String name, float defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredFloatParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Float parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Float value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredFloatParameter(request, name); }
/** * Get a float parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static float getFloatParameter(ServletRequest request, String name, float defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredFloatParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Float parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Float value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredFloatParameter(request, name); }
assertTrue(ServletRequestUtils.getRequiredFloatParameter(request, "param1") == 5.5f); ServletRequestUtils.getRequiredFloatParameter(request, "param2"); fail("Should have thrown ServletRequestBindingException"); assertTrue(ServletRequestUtils.getFloatParameter(request, "param3", 6.5f) == 6.5f); try { ServletRequestUtils.getRequiredFloatParameter(request, "param3"); fail("Should have thrown ServletRequestBindingException"); ServletRequestUtils.getRequiredFloatParameter(request, "paramEmpty"); fail("Should have thrown ServletRequestBindingException");
/** * Get a float parameter, throwing an exception if it isn't found or isn't a number. * @param request current HTTP request * @param name the name of the parameter * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ public static float getRequiredFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { return org.springframework.web.bind.ServletRequestUtils.getRequiredFloatParameter(request, name); }
/** * Get a float parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static float getFloatParameter(ServletRequest request, String name, float defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredFloatParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a float parameter, with a fallback value. Never throws an exception. * Can pass a distinguished value as default to enable checks of whether it was supplied. * @param request current HTTP request * @param name the name of the parameter * @param defaultVal the default value to use as fallback */ public static float getFloatParameter(ServletRequest request, String name, float defaultVal) { if (request.getParameter(name) == null) { return defaultVal; } try { return getRequiredFloatParameter(request, name); } catch (ServletRequestBindingException ex) { return defaultVal; } }
/** * Get a Float parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Float value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredFloatParameter(request, name); }
/** * Get a Float parameter, or {@code null} if not present. * Throws an exception if it the parameter value isn't a number. * @param request current HTTP request * @param name the name of the parameter * @return the Float value, or {@code null} if not present * @throws ServletRequestBindingException a subclass of ServletException, * so it doesn't need to be caught */ @Nullable public static Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { return null; } return getRequiredFloatParameter(request, name); }