前言:
上一篇讲到了SSM项目的搭建,已经使用jetty,返回了json字符串,下面,开始和前端大佬写的页面进行交互,这里前端大佬给我的页面是css+html构成,它整个是一个静态资源,现在我们要做的事就是和我们的java结合,让上面的一些显示信息,和我们的数据库进行联系
上一篇文章的连接: 菜鸡Blue的教程上部
还有一个关于tiles使用的简单理解连接: tiles
开始本项目之前,需要准备几个文件:
1. 前端大佬们的页面
正文:
上一篇,我们可以通过controller,返回给我们一个json字符串,开始前后端互动之前,我们首先得检查自己的controller里面的方法是不是都可以正常运行,这时候,我们就得用到上篇提到的一个关键工具 名字叫postman
,又可以叫他火箭人(我自己的称呼).
第一步 :
完善controller,写入其他的几个方法.
package com.controller;
import com.model.Student;
import com.service.StudentService;
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 org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping(value = "/demo", method = RequestMethod.GET)
@ResponseBody
public List<Student> findAll(Model model) {
List<Student> student = studentService.findAll();