SpringMVC----RESTFUL_CRUD_添加操作&表单标签

1.

1.list.jsp

Add New Employee

2.input.jsp

<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>




Insert title here


    

    
        
        LastName:
        
email:
<% Map genders = new HashMap(); genders.put("1", "male"); genders.put("0", "Female"); request.setAttribute("genders", genders); %> gender:
Department:

2.java代码

package com.yikuan.springmvc.crud.handlers;

import java.util.Map;

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 com.yikuan.springmvc.crud.dao.DepartmentDao;
import com.yikuan.springmvc.crud.dao.EmployeeDao;
import com.yikuan.springmvc.crud.entities.Employee;

@Controller
public class EmployeeHandler {
    
    @Autowired
    private EmployeeDao employeeDao;
    
    @Autowired
    private DepartmentDao departmentDao;
    
    @RequestMapping(value="/emp",method=RequestMethod.POST)
    public String save(Employee employee){
        employeeDao.save(employee);
        return "redirect:/emps";
    }
    
    
    @RequestMapping(value="emp",method=RequestMethod.GET)
    public String input(Map map){
        map.put("departments", departmentDao.getDepartments());
        map.put("employee", new Employee());
        return "input";
    }
    
    @RequestMapping("/emps")
    public String list(Map map){
        map.put("employees", employeeDao.getAll());
        return "list";
    }
}

3.结果

SpringMVC----RESTFUL_CRUD_添加操作&表单标签_第1张图片

SpringMVC----RESTFUL_CRUD_添加操作&表单标签_第2张图片

 

转载于:https://www.cnblogs.com/yikuan-919/p/9740758.html

你可能感兴趣的:(SpringMVC----RESTFUL_CRUD_添加操作&表单标签)