package com.hao.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hao.entity.Clazz;
import com.hao.entity.Student;
import com.hao.service.StudentService;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping("list")
public ModelAndView list(Integer myid) {
System.out.println(myid);
if(myid==null) {
myid=0;
}
ModelAndView mv = new ModelAndView();
List<Student> stuList = studentService.findStudentList();
mv.addObject("stuList", stuList);
mv.addObject("myid", myid);
mv.setViewName("list");
return mv;
}
@RequestMapping("toSup")
public ModelAndView toSup(Integer id,Integer myid) {
System.out.println("id="+id+"myid="+myid);
ModelAndView mv = new ModelAndView();
List<Clazz> claList = studentService.findClazzList();
mv.addObject("claList", claList);
mv.addObject("id", id);
mv.addObject("myid", myid);
mv.setViewName("suppose");
return mv;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="static/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<#list stuList as stu>
<#if (stu.studentid==myid)>
<h5>${stu.studentname!}同学,你好</h5>
</#if>
</#list>
<h3>展示学生列表</h3>
<table>
<tr>
<th>id</th>
<th>name</th>
<th>推荐</th>
</tr>
<#list stuList as stu>
<tr>
<#if (stu.studentid!=myid)>
<th>
${stu.studentid!}
</th>
<th>${stu.studentname!}</th>
<th><button onclick="location='toSup?id=${stu.studentid!}&myid=${myid}'">向他推荐</button></th>
</#if>
</tr>
</#list>
</table>
</body>
</html>
想让别人对你另眼相看,你就得对自己再狠一点。