发表于: 2018-04-07 23:54:15

1 703


今天遇到的问题是,跳转到增加页面,然后写入数据,点击提交,能写入数据库,当时不能重定向到list主页面

写入数据库,说明方法没问题。一开始,我以为事重定向的问题,后来才发现,是我数据类型的问题

  @RequestMapping(value = "/student/addStudent", method = RequestMethod.GET)
public String toAdd() {
return "addStudent";
 }
@RequestMapping(value = "/student", method = RequestMethod.POST)
public String add(Student student) {
studentService.insert(student);
      //model.addAttribute()
      return "redirect:/student/list";
  }
@RequestMapping(value = "/student/list", method = RequestMethod.GET)
public String allGet( Model model) {
List<Student> student = studentService.list();
      model.addAttribute("student", student);
      return "list";
  }

控制器里面是对的,原因出在了mapper里面,当时我把ID的int改成了Long,结果顺手也把 int insert(Student student)改为了Long insert(Student student)

public void deleteByPrimaryKey(Long id);
Student selectByPrimaryKey(Long id);
int insert (Student student);
public int updateByPrimaryKey(Student student);
List<Student> list();
Student selectById(Long id);


二。现在手写一个json出来

@RequestMapping(value = "/student/json" ,method = RequestMethod.GET)
public String json(Model model){
List<Student> studentList = studentService.list();
   model.addAttribute("students",studentList);
   return "jsonList";
}
<json:object escapeXml="false">
<json:array name="学员信息" var="student" items="${students}">
<json:object>
<json:property name="id" value="${student.id}"/>
<json:property name="姓名" value="${student.name}"/>
<json:property name="QQ" value="${student.qq}"/>
<json:property name="major" value="${student.major}"/>
</json:object>
</json:array>
</json:object>


escapeXml没什么用,当时name很有用,删掉会有乱码

三。


明天的计划:提交任务二

遇到的问题:暂无

今天的收获:重装了一个各个软件,尤其是在idea里面加载不了的jar包怎么用mawen加载学会了。

java任务二开始时间:2018.01.25

预计demo时间:2018.02.12

可能有延期风险,原因是:json看不懂,控制器的逻辑看不懂,所以又回看了java语法

禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html 


返回列表 返回列表
评论

    分享到