首页>代码>基于百度人脸识别API的人脸识别信息收集微信小程序>/FaceRecognition-1.3-alpha/后端/人脸识别/src/com/hyj/controller/AddServlet.java
01package com.hyj.controller;
02 
03import java.io.IOException;
04import javax.servlet.ServletException;
05import javax.servlet.annotation.WebServlet;
06import javax.servlet.http.HttpServlet;
07import javax.servlet.http.HttpServletRequest;
08import javax.servlet.http.HttpServletResponse;
09import com.hyj.bean.Result;
10import com.hyj.bean.User;
11import com.hyj.service.UserService;
12 
13/**Servlet implementation class Add
14 * 添加新的人脸数据:每有新的人脸数据出现, 就加入人脸数据库
15 */
16@WebServlet("/v1/user/add")
17public class AddServlet extends HttpServlet {
18    private static final long serialVersionUID = 1L;
19    public AddServlet() {}
20    /**处理请求 并返回响应给小程序
21     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
22     */
23    @Override
24    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
25        // ①接收参数并封装参数
26        String face_id = request.getParameter("face_id");
27        String city = request.getParameter("city");
28        User user = new User();
29        user.setFace_id(face_id);
30        user.setCity(city);
31        // ②将封装好的参数传给Service, 在数据库存储
32        int rowCount = UserService.add(user);
33         
34        // ③根据存储的结果返回不同的响应
35        Result result = null;
36        if (rowCount > 0) result = new Result(0, "添加新的人脸数据成功!");
37        else result = new Result(-1, "添加新的人脸数据失败!");
38        // ④json格式转换, 响应返回给小程序
39        String json = result.toString();
40        response.getWriter().append(json);
41    }
42    /**
43     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
44     */
45    @Override
46    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
47        doGet(request, response);
48    }
49 
50}
最近下载更多
Wwz12345  LV8 2024年6月1日
Artanis  LV1 2023年11月14日
yinyun1985  LV14 2023年8月5日
879222655  LV6 2023年5月19日
fewfsdaf  LV4 2023年4月18日
jk-mack  LV5 2023年2月19日
快乐的程序员  LV25 2023年1月25日
akbar2020  LV9 2022年8月27日
yangzeyu  LV1 2022年4月28日
591231555  LV20 2022年4月18日
最近浏览更多
dushine  LV3 4月14日
tung123 3月12日
暂无贡献等级
微信网友_6955249237250048  LV5 2024年12月28日
lipanlong  LV10 2024年12月3日
fff2003  LV9 2024年9月20日
abdkfksdkf  LV16 2024年9月20日
897258976  LV8 2024年8月29日
ncyhhh  LV2 2024年6月7日
Wwz12345  LV8 2024年6月1日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友