发表于: 2018-03-02 23:53:30
1 623
一。今天主要是准备restful小课堂,但是代码关于小课堂的地方老是运行不对,所以就把小课堂延期到明天,扣了十分。写了一下PPT
二。SSM框架加上restful可以正常运行了,控制器是手打的,如下:
@Controller
public class StudentController{
private static final Logger log = LoggerFactory.getLogger(StudentController.class);
@Resource
private StudentService studentService;
@RequestMapping(Value = "/student/list", method = RequestMethod.GET)
public String getAll(Model model) {
log.info("/student/list GET");
List<Student> studentList = studentService.getAll();
model.addAttribute("studentList",studentList);
log.info("get student size is {}",studentList.size());
return "list";
}
@RequestMapping(value = "/student/{id}",method = Requestmethod.DELETE)
public String delStudent(@PathVariable Long id) {
log.info("/student/{id} DELETE id is {}",id);
studentService.deleteByPrimaryKey(id);
log.info("delete {} success",id);
return "redirect:/student/list";
}
@RequestMapping(value = "/student/a",method = RequestMethod.GET)
public String toAddStudent() {
log.info("open/student/a GET");
return "add";
}
@RequestMapping(value = "/student",method = RequestMethod.POST)
public String addStudent(Student student) {
studentService.insert(student);
log.info("insert student information is {}", student);
return "redirect:/student/list";
}
@RequestMapping(value = "/student/u/{id}", method = RequestMethod.GET)
public String toUpdateStudent(@PathVariable Long id, Model model){
Student student = studentService.selectByPrimaryKey(id);
model.addAttribute("student",student);
return "update";
}
@RequestMapping(value = "/student/{id}",method = RequestMethod.PUT)
public String UpdateStudent(@PathVariable Long id) {
System.out.println(id)
log.info("/student/{id} the request parameters are id:{});
System.out.println(comeFrom);
student.setId(id);
student.setCreateAt(createAt);
int success = studentService.updateBByPrimaryKey(student);
log.info("update student success is {}",success);
return "redirect:/student/list";
}
@RequestMapping(value = "/student/list/json", method = RequestMethod.GET)
public String getAllByJson(Model model) {
List<Student> studentList = studentService.getAll();
model.addAttribute("studentList", studentList);
return "jsonList";
}
list.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Title</title>
</head>
<body>
<h1 style="text-align: center">学生管理系统</h1>
<%--表格--%>
<div style="text-align: center"></div>
<table border="12">
<tr>
<th>ID</th>
<th>创建时间</th>
</tr>
<c:forEach var="student" items="${studentList}">
<%--增加按钮--%>
<form action="${pageContext.request.contextPath}/student/a" method="get">
</c:forEach>
<input type="submit" value="增加">
</form>
<c:forEach var="student" items="${studentList}">
<tr>
<th>${student.id}</th>
<th>${student.createAt}</th>
<%--修改按钮--%>
<th>
<form action="${pageContext.request.contextPath}/student/u/${student.id}" method="get">
<input type="submit" value="修改">
</form>
</th>
<%--删除按钮--%><th>
<form action="${pageContext.request.contextPath}/student/${student.id}" method="post">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" value="删除">
</form>
</th>
</tr>
</c:forEach>
</table>
</body>
</html>
add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>添加</title>
</head>
<body style="text-align: center">
<h2 style="text-align: center">添加学员</h2>
<form action="${pageContext.request.contextPath }/student" method="post">
<br>创建时间<input type="text" name="createAt"style="text-align: center">
</body>
</html>
update.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body style="text-align: center">
<h2 style="text-align: center">编辑学员</h2>
<form action="${pageContext.request.contextPath }/student/${student.id}" method="post" >
<input type="hidden" name="_method" value="PUT">
<br>创建时间<input type="text" name="createAt" value="${student.createAt}" style="text-align: center">
<input type="submit" value="修改">
</form>
</body>
</html>
正常运行如图:
明天的计划:1.看看孟阳师兄的小课堂是怎么讲的2.把我的小课堂SSM代码弄好3.讲小课堂
遇到的问题:restful不太理解,以至于小课堂要延期了
今天的收获:SSM框架的restful可以运行的了
java任务二开始时间:2018.01.25
预计demo时间:2018.02.12
可能有延期风险,原因是:基础比较差,
禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html
评论