SpringBoot整合JOOQ例子(二)
2020-12-13 02:48
标签:builder html time port ISE dao pattern xtend stc 上一篇讲了配置,这篇做了一个例子,和大家共享一下。 项目Demo地址:https://github.com/shileishmily/spring-boot-jooq-demo 1、抽象DAO 2、SysUserDao接口 3、SysUserDaoImpl实现类 4、SysUserService接口 5、SysUserServiceImpl实现类 6、Controller实现 7、本机可以访问http://localhost:8080/swagger-ui.html测试。 SpringBoot整合JOOQ例子(二) 标签:builder html time port ISE dao pattern xtend stc 原文地址:https://www.cnblogs.com/shileibrave/p/11055526.htmlpackage com.suixingpay.jooq;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.suixingpay.jooq.constants.SystemConst;
import org.apache.commons.collections.CollectionUtils;
import org.jooq.DSLContext;
import org.jooq.Table;
import org.jooq.UpdatableRecord;
import org.jooq.impl.UpdatableRecordImpl;
import org.springframework.beans.factory.annotation.Autowired;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
public abstract class BaseDao
package com.suixingpay.jooq.dao;
import com.suixingpay.jooq.entity.tables.pojos.SysUser;
import com.suixingpay.jooq.entity.tables.records.SysUserRecord;
import java.util.List;
public interface SysUserDao {
SysUserRecord findByName(String userName);
List
package com.suixingpay.jooq.dao.impl;
import com.suixingpay.jooq.BaseDao;
import com.suixingpay.jooq.dao.SysUserDao;
import com.suixingpay.jooq.entity.tables.pojos.SysUser;
import com.suixingpay.jooq.entity.tables.records.SysUserRecord;
import org.jooq.Table;
import org.springframework.stereotype.Repository;
import java.util.List;
import static com.suixingpay.jooq.entity.tables.SysUser.SYS_USER;
@Repository("sysUserDao")
public class SysUserDaoImpl extends BaseDao
package com.suixingpay.jooq.service;
import com.suixingpay.jooq.entity.tables.pojos.SysUser;
import com.suixingpay.jooq.entity.tables.records.SysUserRecord;
import java.util.List;
public interface SysUserService {
SysUserRecord newRecord();
int insert(SysUserRecord sysUserRecord);
int update(SysUserRecord sysUserRecord);
int delete(int id);
SysUserRecord get(int id);
List
package com.suixingpay.jooq.service.impl;
import com.suixingpay.jooq.dao.impl.SysUserDaoImpl;
import com.suixingpay.jooq.entity.tables.pojos.SysUser;
import com.suixingpay.jooq.entity.tables.records.SysUserRecord;
import com.suixingpay.jooq.service.SysUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {
@Resource
private SysUserDaoImpl sysUserDao;
@Override
public SysUserRecord newRecord() {
return sysUserDao.newRecord();
}
@Override
public int insert(SysUserRecord sysUserRecord) {
return sysUserDao.insert(sysUserRecord);
}
@Override
public int update(SysUserRecord sysUserRecord) {
return 0;
}
@Override
public int delete(int id) {
return 0;
}
@Override
public SysUserRecord get(int id) {
return null;
}
@Override
public List
package com.suixingpay.jooq.controller;
import com.suixingpay.jooq.entity.tables.pojos.SysUser;
import com.suixingpay.jooq.entity.tables.records.SysUserRecord;
import com.suixingpay.jooq.protocal.Response;
import com.suixingpay.jooq.service.SysUserService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@ApiModel
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
@Autowired
private SysUserService sysUserService;
@ApiOperation(value = "插入用户")
@PostMapping("/insert")
public Response saveUser(@RequestParam String userName,
@RequestParam String realName,
@RequestParam String email,
@RequestParam String phone,
@RequestParam String pswd,
@RequestParam int userStatus) {
SysUserRecord record = sysUserService.newRecord();
record.setUserName(userName);
record.setRealName(realName);
record.setEmail(email);
record.setPhone(phone);
record.setPswd(pswd);
record.setUserStatus(userStatus);
record.setCreateTime(new Timestamp(System.currentTimeMillis()));
sysUserService.insert(record);
return Response.ok();
}
@ApiOperation(value = "根据登录账户查询")
@PostMapping("/findByName")
public Response findByName(@RequestParam String userName) {
SysUserRecord sysUserRecord = sysUserService.findByName(userName);
SysUser sysUser = sysUserRecord.into(SysUser.class);
return Response.ok(sysUser);
}
@ApiOperation(value = "根据真实姓名查询")
@PostMapping("/findByRealName")
public Response findByRealName(@RequestParam String realName) {
List