package com.sxt.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sxt.bean.Goods;
import com.sxt.dao.GoodsDao;
import com.sxt.dao.impl.GoodsDaoImpl;
public class FindIdServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String gid = request.getParameter("gid");
GoodsDao dao = new GoodsDaoImpl();
try {
Goods g = dao.findGoodsById(gid);
PrintWriter out = response.getWriter();
ObjectMapper om = new ObjectMapper();
//日期格式化
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
String json = om.writeValueAsString(g);
out.print(json);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}