package com.example.springboot_jdbc.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* @Author 秋名山码神
* @Date 2023/1/11
* @Description
*/
@RestController
public class JdbcController {
@Autowired
JdbcTemplate jdbcTemplate;
//查询数据库的所有信息
//没有实体类,数据库中的东西,怎么获取
@GetMapping("/userlist")
public List<Map<String, Object>> userList(){
String sql = "select * from user";
List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
return maps;
}
@GetMapping("/addUser")
public String addUser(){
String sql = "INSERT into `user` VALUES (19,'yss',50,'sdfa')";
jdbcTemplate.update(sql);
return "update-ok";
}
@GetMapping("/updateUser")
public String updateUser(){
String sql = "update `uesr` set name = ww where id = 1";
jdbcTemplate.update(sql);
return "update-ok";
}
@GetMapping("/deleteUser")
public String deleteUser(){
String sql = "delete from user where id = 1 ;";
jdbcTemplate.update(sql);
return "update-ok";
}
}