Springboot + 持久层框架JOOQ (2)

这里实现了最基本的功能

Controller @RestController @RequestMapping("/demo/") public class DemoController { @Autowired private DemoService service; @RequestMapping("/insert/user/{name}/{age}") public void insert(@PathVariable String age, @PathVariable String name){ service.insert(new User().setAge(age).setName(name)); } @RequestMapping("/update/user/{name}/{age}") public void update(@PathVariable String age, @PathVariable String name){ service.update(new User().setAge(age).setName(name)); } @RequestMapping("/delete/user/{id}") public void delete(@PathVariable Integer id){ service.delete(id); } @RequestMapping("/select/user/{id}") public User selectByID(@PathVariable Integer id){ return service.selectById(id); } @RequestMapping("/select/user/") public List<User> selectByID(){ return service.selectAll(); } } Service @Service public class DemoServiceImpl implements DemoService { @Autowired DSLContext create; com.example.springbootjooq.generated.tables.User USER = com.example.springbootjooq.generated.tables.User.USER; @Override public void delete(int id) { create.delete(USER).where(USER.ID.eq(id)).execute(); } @Override public void insert(User user) { create.insertInto(USER) .columns(USER.NAME,USER.AGE) .values(user.getName(), user.getAge()) .execute(); } @Override public int update(User user) { create.update(USER).set((Record) user); return 0; } @Override public User selectById(int id) { return create.select(USER.NAME,USER.AGE).from(USER).where(USER.ID.eq(id)).fetchInto(User.class).get(0); } @Override public List<User> selectAll() { return create.select().from(USER).fetchInto(User.class); } }

Demo源码地址

参考

https://blog.csdn.net/weixin_40826349/article/details/89887355

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdfws.html