您好,登錄后才能下訂單哦!
這篇文章主要介紹“springmvc中怎么對數(shù)據(jù)進行保存以及日期參數(shù)的保存過程解析”,在日常操作中,相信很多人在springmvc中怎么對數(shù)據(jù)進行保存以及日期參數(shù)的保存過程解析問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”springmvc中怎么對數(shù)據(jù)進行保存以及日期參數(shù)的保存過程解析”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
1.在Controller類中接受傳入的日期類型的參數(shù)時
<form action="user/todate.do" method="post"> 日期:<input type="text" name="date"/><br /> <input type="submit" value="查看" /> </form>
@RequestMapping("todate.do") public String todate(Date date) { System.out.println(date); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //只要網(wǎng)頁中傳來的數(shù)據(jù)格式為yyyy-MM-dd 就會轉(zhuǎn)化為Date類型 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }
2.當要傳入多個參數(shù)時
<form action="user/list2.do" method="post"> 姓名:<input type="text" name="uname"/><br> 密碼:<input type="text" name="password"/><br> 性別:<input type="text" name="sex"/><br> 年齡:<input type="text" name="age"/><br> 地址:<input type="text" name="address"/><br> 生日:<input type="date" name="birth"><br> <input type="submit" value="提交"> </form>
@RequestMapping("list2.do") public String list2(Users users ) { System.out.println(users); return "list"; } @InitBinder public void initBinder(ServletRequestDataBinder binder){ //只要網(wǎng)頁中傳來的數(shù)據(jù)格式為yyyy-MM-dd 就會轉(zhuǎn)化為Date類型 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); }
Controller數(shù)據(jù)保存
保存至request里
(1)ModelAndView
@RequestMapping("aaa.do") public ModelAndView index() { ModelAndView mv = new ModelAndView(); mv.setViewName("index"); mv.addObject("name","張三"); return mv; }
(2)Model
@RequestMapping("aaa.do") public String index(Model model) { model.addAttribute("name", "李四"); return "index"; }
(3)map
@RequestMapping("aaa.do") public String index(Map<String, Object> map) { map.put("name", "222"); return "index"; }
(4)request
@RequestMapping("list.do") public String list(HttpServletRequest request) { request.setAttribute("name","wang"); return "index2"; }
保存至session里
@RequestMapping("list.do") public String list(HttpSession session) { session.setAttribute("name","wang"); return "index2"; }
保存至application里
@RequestMapping("list.do") public String list(HttpSession session) { session.getServletContext().setAttribute("name","wang"); return "index2"; }
到此,關(guān)于“springmvc中怎么對數(shù)據(jù)進行保存以及日期參數(shù)的保存過程解析”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。