求助,无数据库,做一个前后端分离的学生信息添加删除修改的springboot

package dao;                         //抽象类 

import java.util.ArrayList;
import java.util.List;

import pojo.Student;

public class StudentDao {

	public static List<Student> studentlist=new ArrayList<Student>(); //用于记录学生的信息
	public boolean AddStudent(Student stu)      //添加学生信息
	{
		studentlist.add(stu);
//		 for (int i = 0; i < studentlist.size(); i++) {
//	            Student s = studentlist.get(i);
//	            System.out.println(s);
//	        }
		return true;
	}
	
	public boolean delStudent(int id){           //删除学生信息
		studentlist.remove(id);
//		for (int i = 0; i < studentlist.size(); i++) {
//            Student s = studentlist.get(i);
//            System.out.println(s);
//        }
		return true;
	};
	
	
}

上面的是dao里的,,感觉我写错了而且不知道怎么写

下面的是controller里的

package controller;            //响应用户请求

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import dao.StudentDao;
import pojo.Student;

@Controller
public class StudentController {
	
	private dao.StudentDao studentdao=new dao.StudentDao(); 
	
	@CrossOrigin(origins = "*", maxAge=3600)   //origins:是允许访问的列表(origins=“网址”)
                                                 //maxAge:准备响应前的 缓存持续的 最大时间
    @RequestMapping(value="/addStudent",produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public Map<String, Object>  addStudent(@RequestBody Student student)
	{
		System.out.println(student.getName());
		System.out.println(student.getAge());
		System.out.println(student.getId());
		System.out.println(student.getSex());
		System.out.println(student.getClassroom());
		System.out.println(student.getTel());
		
	    studentdao.AddStudent(student);                      //将数据加到student里
	    
		
		Map<String, Object> map1 = new HashMap<String, Object>(); //返回给用户的信息
		map1.put("success", true);
		return map1;
	}
	@RequestMapping("/delstudent")
	public String delete(@PathVariable int id) {
		dao.StudentDao.delStudent
	}
	
//	public @ResponseBody List<Student> ajaxDemo(@RequestBody Map map) {
//	    List<Student> list = null;
//	    try {
//	        //接收前端传递的map
//	        String str = (String) map.get("id");
//	        String str = (String) map.get("name");
//	        String str = (String) map.get("sex");
//	        //假设做了一系列操作
//	    } catch (Exception e) {
//	        e.printStackTrace();
//	    }
//	    return list;
//	}
	
}

下面的是pojo里的

package pojo;

public class Student {     //定义Student实体类

	private String name;
	private int id;
	private String sex;
	private int age;
	private String classroom;
	private int tel;
	
	public Student(){}
	@Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", classroom='" + classroom + '\'' +
                ", sex='" + sex + '\'' +
                ", tel='" + tel + '\'' +
                '}';
    }
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public int getTel() {
		return tel;
	}
	public void setTel(int tel) {
		this.tel = tel;
	}
	
	public String getClassroom() {
		return classroom;
	}
	public void setClassroom(String classroom) {
		this.classroom = classroom;
	}
	
}

 

1,首先你这个dao用的springboot那就注入就行了,用注解

2,remove方法是根据下表删除,你传递id不对。

3,springmvc的用法也令人费解

http://yun.itheima.com/course/895.html

看这个 springboot教程

1、list存学生信息可以 删除的时候remove(id) 是根据数组(集合)索引删除的数据,不是学生id  可以用stream或者如果没要求干脆用map存key是学生id,value是学生信息,remove(key) key是id就可以了

2、控制层写的一团遭啊 boot可以用注解注入bean  Autowired或者Resource

3、代码刚开始学 最好遵循点命名规范 驼峰第一个字母小写

 

有没有资料我再重新看看

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!

速戳参与调研>>>https://t.csdnimg.cn/Kf0y