首页>代码>spring boot+Spring+Spring MVC+Mybatis+Thymeleaf+Druid开发简单用户增删改查实例>/demo/src/main/java/com/example/demo/controller/UserController.java
package com.example.demo.controller; import com.example.demo.dao.UserMapper; import com.example.demo.domain.User; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by beyondLi on 2017/6/19. */ @Controller public class UserController { // 依赖注入 @Autowired UserMapper userMapper; // @PathVariable Rest风格 路径取参 @RequestMapping("select/{id}") public String select(Model model, @PathVariable("id") int id) { User user = userMapper.selectUserById(id); model.addAttribute(user); return "user"; } @RequestMapping("add") @ResponseBody public String add(Model model, User user) { // 设置用户注册时间 user.setTime(new Date()); userMapper.addUser(user); return "addUser"; } @RequestMapping("Alluser") public String addAll(ModelMap model) { List<User> userAll = userMapper.selectUserAll(); model.addAttribute("userAll", userAll); return "Alluser"; } }

ma406805131 LV19
2024年6月18日
oulingqiao LV13
2023年12月10日
王乐22222 LV10
2022年5月13日
lyws1986 LV17
2021年12月21日
尹恒yingying LV18
2021年10月25日
mudingc木钉 LV30
2021年7月7日
SYX__0707 LV6
2021年4月6日
zuidaima1560 LV3
2020年5月5日
sxxpliaolei LV1
2020年4月24日
mhaogg LV1
2020年4月19日

哪里的完整版 LV8
2月27日
17380184110
2024年6月19日
暂无贡献等级
fengst
2024年6月18日
暂无贡献等级
ma406805131 LV19
2024年6月18日
f22m1a2b2 LV17
2024年5月31日
wwwww816 LV5
2024年5月21日
shuangfu LV25
2024年5月7日
1941549176 LV4
2024年5月6日
vgjbvhkkkk
2024年4月17日
暂无贡献等级
牛牛要爆炸了 LV2
2024年1月17日