发表于: 2017-12-19 21:56:40
1 600
今天完成的事情:
今天mac刚到,主要经理折腾换平台去了.
不过还是解决了一点代码的问题,还是问了于博韬,博韬还是强啊,
package com.controller;
import com.bean.Student;
import com.bean.StudentGet;
import com.bean.StudentPut;
import com.service.IService;
import com.util.ChangeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.ArrayList;
import java.util.List;
/**
* @author Arike
* Create_at 2017/12/14 11:55
*/
@Controller
@RequestMapping("/student")
public class MyController {
@Autowired
private IService servicelmpl;
private Student student;
//增加方法
@RequestMapping(value = "/page",method = RequestMethod.GET)
public String get(){
return "add";
}
@RequestMapping(value = "/method",method = RequestMethod.POST)
public String post(StudentGet sg){
student = ChangeUtil.studentChange(sg);
student.setCreate_at(System.currentTimeMillis()/1000);
servicelmpl.insertStudent(student);
return "redirect:list";
}
//查询所有方法
@RequestMapping(value = "/list",method = RequestMethod.GET)
public String list(Model model){
List<Student> list = servicelmpl.selectAll();
List<StudentPut> list2 = new ArrayList<>();
for (Student student1 : list) {
list2.add(ChangeUtil.timeChange(student1));
}
model.addAttribute("studentList",list2);
return "list";
}
//删除方法
@RequestMapping(value = "/students",method = RequestMethod.DELETE)
public String delete(Long id){
System.out.println(id);
servicelmpl.deleteStudent(id);
return "redirect:list";
}
//下面2个是更新的方法
@RequestMapping(value = "/data",method = RequestMethod.POST)
public String getdata(Long id,Model model){
Student s = servicelmpl.getStudentById(id);
model.addAttribute("newstudent", s);
return "update";
}
@RequestMapping(value = "/id",method = RequestMethod.PUT)
public String update(Long id,StudentGet sg){
student = ChangeUtil.studentChange(sg);
student.setId(id);
servicelmpl.updateStudent(student);
return "forward:list";
}
}
在昨天我使用restful风格进行页面跳转的时候发现,使用forward转发请求的话无法支持post和get跳转,不能给url添加任何的Rest.只能使用redirect重定向才可以.
明天计划的事情:
在新平台上本地使用jetty,重新部署服务.
遇到的问题:
知识的回顾,没有问题.
收获:
mac真他吗好玩.
评论