10月24日 Spring Cloud 周三

本文介绍了一个使用Spring MVC框架实现的学生信息管理系统,该系统能够处理学生列表的展示,并提供了向特定学生推荐功能的页面跳转。系统通过Controller接收请求,调用Service层获取学生和班级数据,然后将数据传递给视图进行展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

想让别人对你另眼相看,你就得对自己再狠一点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值