springboot整合jooq
来源:互联网 发布:全球秒杀 淘宝u站 编辑:程序博客网 时间:2024/06/07 14:09
用的不多,算是个DEMO吧,如有错误欢迎指正
pom文件
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jooq</artifactId></dependency>
<build> <plugins> <!--默认打包方式--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.1.RELEASE</version> <configuration> <executable>true</executable> <classifier>exec</classifier> </configuration> </plugin> <!--jooq 构建构建工具--> <plugin> <groupId>org.jooq</groupId> <artifactId>jooq-codegen-maven</artifactId> <version>${jooq.version}</version> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> </dependencies> <configuration> <!-- JDBC connection parameters --> <jdbc> <driver>com.mysql.jdbc.Driver</driver> <url>jdbc:mysql://120.25.211.83:3306</url> <user>root</user> <password>123</password> </jdbc> <generator> <database> <name>org.jooq.util.mysql.MySQLDatabase</name> <includes>.*</includes> <excludes/> <!--数据库名--> <!--inputSchema 输入模式--> <schemata> <schema> <inputSchema>lost_and_found</inputSchema> </schema> <schema> <inputSchema>wyh</inputSchema> </schema> </schemata> <!--强制类型--> <forcedTypes> <forcedType> <name>BOOLEAN</name> <types>(?i:TINYINT(\s*\(\d+\))?(\s*UNSIGNED)?)</types> </forcedType> </forcedTypes> </database> <generate> <pojos>true</pojos> <!--<daos>true</daos>--> <deprecated>true</deprecated> </generate> <target> <packageName>com.example.domain.jooq</packageName> <directory>src/main/java</directory> </target> </generator> </configuration> </plugin> </plugins> </build>
引入pom后在maven插件中可以生成对应数据库中的实体
生成的实体如下
jooq不需要dao层,直接上service
/** * Created by rj-wyh on 2017/4/11. */public interface DepartmentService { List<Department> findAll(); String save(Department department);}
import com.wyh.data.domain.jooq.tables.pojos.Department;import com.wyh.data.domain.jooq.tables.records.DepartmentRecord;import com.wyh.data.service.DepartmentService;import org.jooq.DSLContext;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.ArrayList;import java.util.List;import static com.wyh.data.domain.jooq.tables.Department.DEPARTMENT;/** * Created by rj-wyh on 2017/4/11. */@Servicepublic class DepartmentServiceImpl implements DepartmentService { @Autowired private DSLContext create; @Override public List<Department> findAll() { List<DepartmentRecord> departmentRecords= create .select() .from(DEPARTMENT) .fetchInto(DepartmentRecord.class); List<Department> departmentList = new ArrayList<>(); for (DepartmentRecord departmentRecord: departmentRecords) { Department department = new Department(); department.setName(departmentRecord.getName()); department.setEmployeesNum(departmentRecord.getEmployeesNum()); department.setId(departmentRecord.getId()); department.setManager(departmentRecord.getManager()); departmentList.add(department); } return departmentList; } @Override public String save(Department department) { create .insertInto(DEPARTMENT, DEPARTMENT.NAME, DEPARTMENT.EMPLOYEES_NUM, DEPARTMENT.MANAGER) .values(department.getName(), department.getEmployeesNum(), department.getManager()) .execute(); return "success"; }}
上controller层
import com.wyh.data.domain.jooq.tables.pojos.Department;import com.wyh.data.domain.pojo.Result;import com.wyh.data.service.DepartmentService;import com.wyh.data.utils.ResultUtil;import io.swagger.annotations.ApiOperation;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.validation.BindingResult;import org.springframework.validation.annotation.Validated;import org.springframework.web.bind.annotation.*;/** * Created by rj-wyh on 2017/4/11. */@RestController@RequestMapping("/department")public class DepartmentController { @Autowired private DepartmentService departmentService; @PostMapping("/save") @ApiOperation(value = "保存部门") public Result save(@RequestBody@Validated Department department, BindingResult bindingResult){ if (bindingResult.hasErrors()){ return ResultUtil.error(bindingResult.getFieldError().getDefaultMessage(), "-1"); } return ResultUtil.success(departmentService.save(department)); } @GetMapping("/findAll") @ApiOperation(value = "查找全部部门") public Result findAll(){ return ResultUtil.success(departmentService.findAll()); }}
阅读全文
1 0
- springboot整合jooq
- springboot整合jooq
- springboot+jooq
- springboot+jooq+thymeleaf
- SpringBoot学习:SpringBoot整合mybatis
- SpringBoot整合Mybatis(分层整合)
- springboot整合freemarker
- SpringBoot和Mybatis整合
- springboot整合jsp
- springboot 整合mybatis
- springboot整合swagger
- springboot+mybatis+dubbo整合
- springboot mybaits mysql 整合
- springboot整合jedisCluster
- springboot整合dubbox
- SpringBoot整合MyBatis
- SpringBoot整合Mybatis
- springBoot整合mybatis
- Spring JdbcTemplate详解
- js URL编解码的应用说明
- python下RSA加密解密以及跨平台问题
- Spring Cloud 5分钟搭建教程(附上一个分布式日志系统项目作为参考)
- Mybatis整合Spring -- typeAliasesPackage
- springboot整合jooq
- 使用 webdriver报错 ElementNotInteractableException: Message: 的解决办法
- 汽车光有语音指令真的out了!
- 一款实用好玩儿的背单词程序
- Unity3d中的Awake()、OnEnable()、Start()等默认函数的执行顺序和生命周期
- AndroidStudio 打Jar包
- 流动的推荐系统
- 移动app测试之怎么避免bug漏测
- mysql不支持Intersect交集,改版取交集