package com.ischoolbar.programmer.controller; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.ischoolbar.programmer.entity.Clazz; import com.ischoolbar.programmer.entity.Grade; import com.ischoolbar.programmer.page.Page; import com.ischoolbar.programmer.service.ClazzService; import com.ischoolbar.programmer.service.GradeService; import com.ischoolbar.programmer.util.StringUtil; /** * 班级信息管理 * @author llq * */ @RequestMapping("/clazz") @Controller public class ClazzController { @Autowired private GradeService gradeService; @Autowired private ClazzService clazzService; /** * 班级列表页 * @param model * @return */ @RequestMapping(value="/list",method=RequestMethod.GET) public ModelAndView list(ModelAndView model){ model.setViewName("clazz/clazz_list"); List<Grade> findAll = gradeService.findAll(); model.addObject("gradeList",findAll ); model.addObject("gradeListJson",JSONArray.fromObject(findAll)); return model; }给这段代码加上注释
时间: 2023-12-16 18:05:48 浏览: 112
```
//导入所需的类
package com.ischoolbar.programmer.controller;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.ischoolbar.programmer.entity.Clazz;
import com.ischoolbar.programmer.entity.Grade;
import com.ischoolbar.programmer.page.Page;
import com.ischoolbar.programmer.service.ClazzService;
import com.ischoolbar.programmer.service.GradeService;
import com.ischoolbar.programmer.util.StringUtil;
/**
* 班级信息管理
* @author llq
*/
@RequestMapping("/clazz")
@Controller
public class ClazzController {
//自动注入GradeService和ClazzService
@Autowired
private GradeService gradeService;
@Autowired
private ClazzService clazzService;
/**
* 班级列表页
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
//设置视图的名称
model.setViewName("clazz/clazz_list");
//获取所有年级的列表
List<Grade> findAll = gradeService.findAll();
//将年级列表放入ModelAndView中
model.addObject("gradeList",findAll );
//将年级列表转换为JSON格式,并放入ModelAndView中
model.addObject("gradeListJson",JSONArray.fromObject(findAll));
return model;
}
}
```
阅读全文