发表于: 2018-03-01 23:50:37

1 689


一。今天改SSM,增加可以,删除可以,编辑可以跳转,写完之后提交不可以。还是rest的问题

public class StudentController {
@Autowired
   StudentService studentService;

   @RequestMapping(value = "/listStudent",method = RequestMethod.GET)
public ModelAndView listStudent(Page page){

ModelAndView mav = new ModelAndView();
       List<Student> ss= studentService.list(page);
       int total = studentService.total();

       page.caculateLast(total);

       // 放入转发参数
       mav.addObject("ss", ss);
       // 放入jsp路径
       mav.setViewName("listStudent");
       return mav;
   }

@RequestMapping(value = "/addStudent",method = RequestMethod.POST)
public ModelAndView addStudent(Student student){
studentService.add(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }
@RequestMapping(value = "/deleteStudent/{id}",method = RequestMethod.DELETE)
public ModelAndView deleteStudent(Student student){
studentService.delete(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }
@RequestMapping(value = "editStudent/{id}",method = RequestMethod.POST)
public ModelAndView editStudent(Student student){
Student s= studentService.get(student.getId());
       ModelAndView mav = new ModelAndView("editStudent");
       mav.addObject("s", s);
       return mav;
   }
@RequestMapping(value = "updateStudent/{id}",method = RequestMethod.PUT)
public ModelAndView updateStudent(Student student){
studentService.update(student);
       ModelAndView mav = new ModelAndView("redirect:/listStudent");
       return mav;
   }

二。根据教程做了一个图书馆的SSM,双表联查。看看效果怎么样

架构如下:

@Controller
@RequestMapping("/book") // url:/模块/资源/{id}/细分 /seckill/list
public class BookController {
   private Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

   @Autowired
   private BookService bookService;

   @RequestMapping(value = "/list", method = RequestMethod.GET)
   private String list(Model model) {
       List<Book> list = bookService.getList();
       model.
addAttribute("list", list);
       // list.jsp + model = ModelAndView
       return "list";// WEB-INF/jsp/"list".jsp
   }

@RequestMapping(value = "/{bookId}/detail", method = RequestMethod.GET)
private String detail(@PathVariable("bookId") Long bookId, Model model) {
if (bookId == null) {
return "redirect:/book/list";
       }
       Book book = bookService.getById(bookId);
       if (book == null) {
return "forward:/book/list";
       }
       model.addAttribute("book", book);
       return "detail";
   }

//ajax json
   @RequestMapping(value = "/{bookId}/appoint", method = RequestMethod.POST, produces = {
"application/json; charset=utf-8" })
@ResponseBody
   private Result<AppointExecution> appoint(@PathVariable("bookId") Long bookId, @RequestParam("studentId") Long studentId) {
if (studentId == null || studentId.equals("")) {
return new Result<>(false, "学号不能为空");
       }
//AppointExecution execution = bookService.appoint(bookId, studentId);//错误写法,不能统一返回,要处理异常(失败)情况
       AppointExecution execution = null;
       try {
           execution = bookService.appoint(bookId, studentId);
       } catch (NoNumberException e1) {
           execution = new AppointExecution(bookId, AppointStateEnum.NO_NUMBER);
       } catch (RepeatAppointException e2) {
           execution = new AppointExecution(bookId, AppointStateEnum.REPEAT_APPOINT);
       } catch (Exception e) {
           execution = new AppointExecution(bookId, AppointStateEnum.INNER_ERROR);
       }
return new Result<AppointExecution>(true, execution);
   }

别的都没问题,唯有控制器报错:

Error:(30, 14) java: 找不到符号

  符号:   方法 addAttribute(java.lang.String,java.util.List<com.how2java.lyf.entity.Book>)

  位置: 类型为javax.enterprise.inject.Model的变量 model

Error:(44, 14) java: 找不到符号

  符号:   方法 addAttribute(java.lang.String,com.how2java.lyf.entity.Book)

  位置: 类型为javax.enterprise.inject.Model的变量 model

搞不定,明天再搞。


三。准备小课堂的APP,小课堂的题目是:什么是RESTFUL?REST的请求方法有哪些,有什么区别?

明天的计划:准备小课堂

遇到的问题:项目还是无法运行

今天的收获:做了个图书馆的项目,后天做好;

java任务二开始时间:2018.01.25

预计demo时间:2018.02.12

可能有延期风险,原因是:基础比较差,

禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html



返回列表 返回列表
评论

    分享到