package com.yh.controller;
import com.yh.model.User;
import com.yh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.persistence.Id;
import java.util.List;
@Controller
public class UserController {
@Autowired
UserService userService;
//查询所有的信息
@GetMapping("all")
public String all(Model model){
List<User> users = userService.findAll();
model.addAttribute("users",users);
return "user";
}
@RequestMapping("toAdd")
public String addh() {
return "add";
}
// 添加信息
@RequestMapping("add")
public String addUser(User user) {
userService.addUser(user);
return "redirect:all";
}
// 主键查询,回显数据
@RequestMapping("findById")
public String findById(Integer id,Model model){
User user=userService.findById(id);
model.addAttribute("user", user);
return "update";
}
//修改数据信息
@RequestMapping("toUpdate/{id}")
public String toUpdate(@PathVariable("id") Integer id,
Model model){
User user= userService.findById(id);
model.addAttribute("user",user);
return "update";
}
@RequestMapping("/update")
public String update(User user){
userService.update(user);
return "redirect:all";
}
//删除信息
@RequestMapping("/delete/{id}")
public String deleteById(@PathVariable("id")
Integer id){
userService.deleteById(id);
return "redirect:/all";
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SbringBoot的整合项目
共32个文件
html:10个
java:7个
class:7个
需积分: 0 0 下载量 33 浏览量
2023-07-07
20:43:20
上传
评论
收藏 64KB ZIP 举报
温馨提示
做了简单增删改查业务处理,数据库表自已建立。
资源推荐
资源详情
资源评论
收起资源包目录
day07_ks01.zip (32个子文件)
day07_ks01
HELP.md 853B
pom.xml 4KB
src
test
java
com
yh
Day07Ks01ApplicationTests.java 210B
main
resources
application.properties 870B
templates
user.html 1KB
css
static
bootstrap.min.css 119KB
update.html 812B
index.html 79B
add.html 632B
user.html 1KB
java
com
yh
Day07Ks01Application.java 317B
mapper
UserMapper.java 207B
controller
UserController.java 2KB
service
UserService.java 389B
impl
UserServiceImpl.java 1014B
model
User.java 261B
target
classes
application.properties 870B
templates
user.html 1KB
static
bootstrap.min.css 119KB
update.html 812B
index.html 79B
add.html 632B
user.html 1KB
com
yh
mapper
UserMapper.class 330B
controller
UserController.class 2KB
Day07Ks01Application.class 698B
service
UserService.class 387B
impl
UserServiceImpl.class 2KB
model
User.class 2KB
test-classes
com
yh
Day07Ks01ApplicationTests.class 526B
generated-test-sources
test-annotations
generated-sources
annotations
.gitignore 395B
day07_ks01.iml 10KB
共 32 条
- 1
资源评论
未来的代码
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功