只是想知道是否有一种更优雅或标准的方式来处理可选参数,或者你是否必须检查每一个是否为空.我有10个可选参数,所以它有点难看.
理想情况下,我想要像bash命令:getopts.
public class MapImageServlet extends HttpServlet {
... constructor and other methods ...
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// OPTIONAL PARAMETERS
if(request.getParameter("boarderSize") != null){
double boarderSize = Double.valueOf(request.getParameter("boarderSize");
}
if(request.getParameter("boarderThickness") != null){
double boarderThickness = Double.valueOf(request.getParameter("boarderThickness");
}
if(request.getParameter("boarderColor") != null){
double boarderColor = Double.valueOf(request.getParameter("boarderColor");
}
... do stuff with the parameters ...
}
... other methods ...
}