小项目(一)(问题篇)

1.前端展示界面输出格式的问题

 

 

 

 

2.

 

 

 发现后面要用

new user user 不好区分

所以entity层里的user改成User

 

3.添加用户时中文乱码问题

 

 

 req.setCharacterEncoding("UTF-8");

4.点删除删不掉

 

 

 原因:集合用的是list,list无法凭借一个id属性就删除整个对象

换成map就可以用id来删除对象

    private static Map<Integer,User> map=new HashMap<>();
   private static Map<Integer,User> map=new HashMap<>() ;
    static {
        map.put(1,new User(1,"张三","13124"));
        map.put(2,new User(2,"李四","13125"));
        map.put(3,new User(3,"王五","13126"));
    }

 

  map.remove(id);

5.

 

 

 

  req.setAttribute("map", map);

变成

    req.setAttribute("map", map.values());

 

 

 

6.

删除后出现

 

 将

  req.getRequestDispatcher("index.jsp").forward(req,resp);

变成

      resp.sendRedirect("/user");

原因:

每当

 

 刷新一次,就调用了一次doget函数,doget里method=null时将集合map传到前端

 

posted @ 2021-01-27 12:12  Hanabi_521  阅读(62)  评论(0)    收藏  举报