@Controller
@RequestMapping("/student")
public class StudentController {
@Autowired
private StudentService studentService;
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String createStudent(@ModelAttribute("student") Student student, Model model) {
studentService.create(student);
model.addAttribute("message", "Student created successfully!");
return "create_success";
}
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String listStudents(Model model) {
List<Student> students = studentService.getAll();
model.addAttribute("students", students);
return "student_list";
}
}
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<mvc:annotation-driven />
<bean id="studentService" class="com.example.StudentServiceImpl" />
</beans>