初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))

SpringMVC实战--构建学生管理系统(15)

首页部分成绩录入页面(编辑/删除/批量录入功能)制作

(源代码见仓库:https://gitee.com/jianghao233/course)

新建 scoreInManager.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


	
		
		
		
		
		
		
	
	
		
学生成绩表
班级 学生学号 学生名称 学年 学期 课程 学分 成绩 操作
${c.classname } ${c.stunum } ${c.stuname } ${c.year } ${c.term } ${c.coursename } ${c.score } 编辑 删除

新建 ScoreInController.java

package com.neuedu.controller;

import java.util.List;

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 com.neuedu.po.Selection;
import com.neuedu.service.ScoreInService;
import com.neuedu.vo.ScoreInVO;

@Controller
@RequestMapping("/scorein")
public class ScoreInController {
	
	@Autowired
	private ScoreInService scoreInService;
	
	@RequestMapping({"/","/list"})
	public String list(Model model) {
	
		List list = scoreInService.getList();
		model.addAttribute("list", list);
		
		return "admin/scoreInManager";
	}
	
	@RequestMapping("/batModify")
	public String batModify(ScoreInVO scoreInVO) {
		scoreInService.batModify(scoreInVO.getSelections());
		return "redirect:/scorein/";
		
	}
	
	@RequestMapping("/modify")
	public String modify(Selection selection) {
		scoreInService.modify(selection);
		return "redirect:/scorein/";
	}
	
	@RequestMapping("/deleteScore")
	public String deleteScore(Integer selid) {
		scoreInService.deleteScore(selid);
		return "redirect:/scorein/";
	}
	
	
	
}

修改 index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>


	
		
		
		
	
	
		 
		
		
	

新建 ScoreInVO.java

package com.neuedu.vo;

import java.util.List;

import com.neuedu.po.Selection;

public class ScoreInVO extends Selection{
	private String classname;
	private String stunum;
	private String stuname;
	private String coursename;
	private double score;
	
	List selections;
	
	
	public List getSelections() {
		return selections;
	}
	public void setSelections(List selections) {
		this.selections = selections;
	}
	public String getClassname() {
		return classname;
	}
	public void setClassname(String classname) {
		this.classname = classname;
	}
	public String getStunum() {
		return stunum;
	}
	public void setStunum(String stunum) {
		this.stunum = stunum;
	}
	public String getStuname() {
		return stuname;
	}
	public void setStuname(String stuname) {
		this.stuname = stuname;
	}
	public String getCoursename() {
		return coursename;
	}
	public void setCoursename(String coursename) {
		this.coursename = coursename;
	}
	public double getScore() {
		return score;
	}
	public void setScore(double score) {
		this.score = score;
	}
	
}

新建 ScoreInMapper.java

package com.neuedu.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.neuedu.vo.ScoreInVO;

public interface ScoreInMapper {
	
	public List getList();
	public void deleteScore(@Param("selid")Integer selid);

}

新建 ScoreInMapper.xml




	
	
	
		update selection set grade = null where selid = #{selid}
	
	

新建 ScoreInService.java

package com.neuedu.service;

import java.util.List;

import com.neuedu.po.Selection;
import com.neuedu.vo.ScoreInVO;

public interface ScoreInService {
	public List getList();
	
	public void batModify(List selections);
	
	public void modify(Selection selection);
	
	public void deleteScore(Integer selid);
	
}

新建 ScoreInServiceImpl.java

package com.neuedu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neuedu.mapper.ScoreInMapper;
import com.neuedu.mapper.SelectionMapper;
import com.neuedu.po.Selection;
import com.neuedu.service.ScoreInService;
import com.neuedu.vo.ScoreInVO;

@Service
public class ScoreInServiceImpl implements ScoreInService {
	
	@Autowired
	private ScoreInMapper scoreMapper;
	@Autowired
	private SelectionMapper selMapper;

	@Override
	public List getList() {		
		return scoreMapper.getList();
	}

	@Override
	public void batModify(List selections) {
		for (Selection s : selections) {
			selMapper.updateByPrimaryKeySelective(s);
		}		
	}

	@Override
	public void modify(Selection selection) {
		selMapper.updateByPrimaryKeySelective(selection);		
	}

	@Override
	public void deleteScore(Integer selid) {
		scoreMapper.deleteScore(selid);
	}
	
	

}

输出:进入成绩录入页面---输入成绩--点击编辑---点击删除
初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))_第1张图片

初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))_第2张图片

初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))_第3张图片

输入全部成绩--点击 批量录入 ---所有成绩全部添加到数据库

初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))_第4张图片

初识 Spring(25)---(SpringMVC实战--构建学生管理系统(15))_第5张图片

你可能感兴趣的:(Java,#,Spring,突破Spring框架)