spring:Springboot + 持久层框架JOOQ( 三 )


           <excludes></excludes>
       </database>

       <target>
           <!-- The destination package of your generated classes (within the destination directory) -->
           <packageName>com.example.springbootjooq.generated</packageName>

           <!-- The destination directory of your generated classes. Using Maven directory layout here -->
           <directory>src/main/java</directory>
       </target>
   </generator></configuration>

自动生成#

  • 我们在mysql中创建demo库 , 并创建一张User表如下(点的比较快 , 年龄字段用的varchar勿喷)
Copymysql> describe user;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(45) | NO   |     | NULL    |                |
| age   | varchar(45) | NO   |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

  • 执行compile , 会把表结构的抽象 , 以及表对应的pojo自动生成到指定目录 , 然后就可以愉快的coding了
Copymvn clean compile

Demo#这里实现了最基本的功能
ControllerCopy@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();