package com.landaiqing.servlet.system;



import com.alibaba.fastjson.JSONObject;
import com.landaiqing.entity.UserEntity;
import com.landaiqing.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/listManage")
public class ListManage extends HttpServlet {
    private UserService userService;

    {
        try {
            userService = new UserService();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        List<UserEntity> userEntities=userService.list();
        String jsonString = JSONObject.toJSONString(userEntities);
        writer.println(jsonString);
        writer.close();
//        req.setAttribute("listManage",jsonString);
//        req.getRequestDispatcher("./System/index.jsp").forward(req,resp);
    }
}