// 查詢一個(gè)位面
public String queryById() throws IOException{
//獲取response對(duì)象
HttpServletResponse response = ServletActionContext.getResponse();
//輸出內(nèi)容的格式(解決輸出亂碼問(wèn)題)
response.setContentType("text/html;charset=utf-8");
//獲取輸出流(至于等于response.getWriter()是因?yàn)楂@取PrintWriter的流韭寸,但是要反映到response)
PrintWriter out = response.getWriter();
//獲取request兌現(xiàn)
HttpServletRequest request=ServletActionContext.getRequest();
//得到頁(yè)面?zhèn)鬟^(guò)來(lái)的參數(shù)(傳過(guò)來(lái)的是String類(lèi)型忆谓,要轉(zhuǎn))
int id=Integer.parseInt(request.getParameter("id"));
//根據(jù)ID查到的數(shù)據(jù)说墨,賦給weimian對(duì)象
WeiMian weimian = wm.queryById(id);
//獲取gson對(duì)象,bin里面需要導(dǎo)入gson的jar包(轉(zhuǎn)json數(shù)據(jù)類(lèi)型)
Gson gson = new Gson();
//將weimian轉(zhuǎn)成json類(lèi)型數(shù)據(jù)逃魄,然后通過(guò)PrintWriter流反映到response返回到頁(yè)面
out.print(gson.toJson(weimian));
//關(guān)閉流
out.close();
//如果不需要跳轉(zhuǎn)的話,這里就不需要給出返回值
return null;
}