package com.kxs.adminap.controller; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Dictionary; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import com.kxs.adminap.dao.TestTablerepository; import com.kxs.adminap.enity.TestTable; import com.kxs.adminap.service.DbConn; import com.kxs.adminap.util.RedisUtils; import jakarta.annotation.Resource; @RestController public class TestController { @Autowired private TestTablerepository testTablerepository; @Resource RedisUtils redisUtils; @RequestMapping("/") public String home() { String result = "hey,java"; return result; } @RequestMapping("/test") public String test() { String result = "ok"; // redisUtils.set("javaset", "ohyeah"); // result += redisUtils.get("javaset"); // redisUtils.set("hahaha", "咔咔咔咔"); // result += redisUtils.get("hahaha"); // redisUtils.set("kkk", 123); // result += redisUtils.getInteger("kkk"); TestTable d = testTablerepository.findById(2).get(); redisUtils.addList("test:list", d); return result; } @RequestMapping("/test2") public List test2() { return redisUtils.getList("test:list"); } @RequestMapping("/test3") public TestTable test3() { return (TestTable)redisUtils.getList("test:list").get(0); } @RequestMapping("/add") public String add() { String result = "ok"; TestTable d = new TestTable(); d.setName("测试java"); try { d.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2023-07-07 15:15:15")); } catch (ParseException e) { e.printStackTrace(); } d.setSex(12345d); d.setContents("水电费及时反馈海上繁花科技
asdasdasd"); d.setIsOk(true); testTablerepository.save(d); return result; } @RequestMapping("/update") public String update(Integer id) { String result = "ok"; TestTable d = testTablerepository.findById(id).get(); d.setName("修改名称"); d.setContents("修改的内容"); testTablerepository.save(d); return result; } @RequestMapping("/delete") public String delete(Integer id) { String result = "ok"; testTablerepository.deleteById(id); return result; } @RequestMapping("/all") public @ResponseBody Iterable getAll() { return testTablerepository.findAll(); } @RequestMapping("/one") public @ResponseBody TestTable getOne(Integer id) { var item = testTablerepository.findById(id); return item.orElse(new TestTable()); } @RequestMapping("/search") public @ResponseBody Iterable getSearch() { var item = testTablerepository.findByCondition("name='测试java'"); return item; } @RequestMapping("/sql") public List> sql() { return DbConn.Query("select * from ApiVersion"); } @RequestMapping("/sqlop") public String sqlop(Integer id) { DbConn.Op("delete from ApiVersion where Id=" + id); return "ok"; } }