首页>代码>spring boot+mybatis+thymeleaf开发实现基于内嵌式数据库H2的增删该查入门简单实例>/yourProject/src/main/java/com/example/demo/controller/IndexController.java
package com.example.demo.controller; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.example.demo.entity.Student; import com.example.demo.enums.GenderTypeEnum; import com.example.demo.service.StudentService; @Controller public class IndexController { @Resource private StudentService studentService; @RequestMapping("/") public String goIndex(ModelMap map) { List<Student> list = new ArrayList<Student>(); list = studentService.selectAll(); map.addAttribute("list", list); return "thymeleaf/index"; } @RequestMapping("/goAdd") public String goAdd(Model model) { model.addAttribute("student", new Student()); List<GenderTypeEnum> list = new ArrayList<GenderTypeEnum>(); list.add(GenderTypeEnum.MALE); list.add(GenderTypeEnum.FEMALE); list.add(GenderTypeEnum.UNKNOWN); model.addAttribute("list",list); return "thymeleaf/add"; } @RequestMapping("/goUpdate") public String goUpdate(Model model,HttpServletRequest request) { String id = request.getParameter("id"); int selId = Integer.valueOf(id); Student student = studentService.selStudentById(selId); List<GenderTypeEnum> list = new ArrayList<GenderTypeEnum>(); list.add(GenderTypeEnum.MALE); list.add(GenderTypeEnum.FEMALE); list.add(GenderTypeEnum.UNKNOWN); model.addAttribute("list",list); model.addAttribute("student", student); return "thymeleaf/update"; } }

ma406805131 LV19
2024年5月11日
anopsign LV1
2022年6月30日
caozongan LV19
2022年1月10日
swordking LV1
2021年6月22日
1690356080 LV38
2021年6月15日
yongjava21 LV26
2021年2月19日
阿风啦 LV14
2021年1月24日
时代信念 LV4
2020年12月24日
hjd3983 LV10
2020年11月22日
vaterz LV25
2020年11月18日