preface

In the process of using Jeecg, I experienced the convenience of the code generator. It is very fast to generate a set of CRUD code covering both front and back ends based on the tables in the database. But Jeecg’s template does not follow the RESTful style specification and uses result. error to return an error condition instead of throwing an exception. If we can get the generated code to our taste, it will make us more comfortable later in the development process.

Take a look at the official documentation

The generator official documentation: doc.jeecg.com/2043918 the official documentation gives the path to the code generator template in the Online form: Jeecg-boot-module-system /jeecg.code-template-online

We use the one-to-many embedded Table template as an example to demonstrate this, and modify it in several ways:

  1. Complies with RESTful apis
  2. The I prefix of the interface is deleted
  3. Mapper and Service interfaces remove redundant public modifiers
  4. ServiceImpl uses @Resource for Mapper injection because @AutoWired is popular for Mapper in idea
  5. The Controller’s getById interface throws an exception when no data is queried instead of returning result.error ()
  6. Change the return value to entity type instead of Result< based on ResponseAdvice? >

First enter the selected package jeecg-boot-module-system/jeecg.code-template-online as shown below

1. Complies with RESTful apis

Open the Controller template ${entityName} controller.javai and modify it separately using the search function

@GetMapping(value = "/list")
@PostMapping(value = "/add")
@PutMapping(value = "/edit")
@DeleteMapping(value = "/delete")
@GetMapping(value = "/queryById")
@GetMapping(value = "/query${sub.entityName}ByMainId")
Copy the code

Modified to

@GetMapping("/list")
@PostMapping
@PutMapping
@DeleteMapping
@GetMapping
@GetMapping("/${sub.entityName}ByMainId")
Copy the code

Open vue.${entityName}.vuei to search for url keywords

url: {
  list: '${urlPrefix}/list',
  delete: '${urlPrefix}/delete',
  deleteBatch: '${urlPrefix}/deleteBatch',
  exportXlsUrl: '${urlPrefix}/exportXls',
  importExcelUrl: '${urlPrefix}/importExcel',
},

修改为

url: {
  list: '${urlPrefix}/list',
  delete: '${urlPrefix}',
  deleteBatch: '${urlPrefix}/batch',
  exportXlsUrl: '${urlPrefix}/exportXls',
  importExcelUrl: '${urlPrefix}/importExcel',
},
Copy the code

${entityName}Form.vuei

url: { add: "/${entityPackage}/${entityName? uncap_first}/add", edit: "/${entityPackage}/${entityName? uncap_first}/edit", <#list subTables as sub><#rt/> ${sub.entityName? uncap_first}: { list: '/${entityPackage}/${entityName? Uncap_first}/query${sub.entityName}ByMainId'}, </#list>}} uncap_first}", edit: "zu/${entityName? uncap_first}", <#list subTables as sub><#rt/> ${sub.entityName? uncap_first}: { list: '/zu/${entityName? uncap_first}/${sub.entityName}ByMainId' }, </#list> }Copy the code

Remaining vue. SubTables. [1 – n] SubTable. Vuei

{listByMainId: '${urlPrefix}/query${sub.entityName}ByMainId',} '${urlPrefix}/${sub.entityName}ByMainId', },Copy the code

Above we have completed the RESTful template adjustment in Jeecg, to be continued.