In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about how to use EasyCode to generate springboot+mybatis basic programs. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. Preface
This article will share an easycode generation method that I personally use, which can be run directly after generation, which means that the generated code will be more standardized. Normalization means more constraints.
II. Text 2.1 basic premise 2.1.1springboot configuration
Introduce the required jar package
Pom.xml adds a dependency
Org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-web mysql mysql-connector-java 5.1.47 Org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 com.github.pagehelper pagehelper-spring-boot-starter 1.2.5 com.alibaba fastjson 1.2.76 Io.springfox springfox-boot-starter 3.0.0 com.github.xiaoymin swagger-bootstrap-ui 1.9.6 org.projectlombok lombok 1.18.10
Application.yml configuration
Spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://ip:3306/dbname?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC username: xxx password: xxxmybatis: type-aliases-package: xxx.entity mapper-locations: classpath:mapper/*.xml# pagehelperpagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql#showSqllogging: level: top: yuechenc: yueduapi: mapper: debug2.1.1 basic tool class
The following is my personal packaged pagehelper paging tool class and unified return as well as swagger configuration
Pagehelper utility class
As shown in the above figure, create a new directory common.page/common.util under the same directory as the startup class
Create a new class PageRequest.java in the page directory
Package xxx.common.page;/** * @ author Zhiwei Wang * @ version $1.0 * @ description paging request * @ date 9:25 on 2022-1-19 * @ history * / public class PageRequest {/ * current page number * / private int pageNum; / * number per page * / private int pageSize; public PageRequest (int start, int limit) {pageNum=start; pageSize=limit } public int getPageNum () {return pageNum;} public void setPageNum (int pageNum) {this.pageNum = pageNum;} public int getPageSize () {return pageSize;} public void setPageSize (int pageSize) {this.pageSize = pageSize;}}
Create a new class PageResult.java in the page directory
Package xxx.common.page;import java.util.List;/** * @ author Zhiwei Wang * @ version $1.0 * @ name PageResult * @ description pagination returns results * @ date 9:25 on 2022-1-19 * @ history * / public class PageResult {/ * * current page number * / private int pageNum; / * number per page * / private int pageSize / * Total number of records * / private long totalSize; / * * Total page numbers * / private int totalPages; / * data model * / private List content; public int getPageNum () {return pageNum;} public void setPageNum (int pageNum) {this.pageNum = pageNum } public int getPageSize () {return pageSize;} public void setPageSize (int pageSize) {this.pageSize = pageSize;} public long getTotalSize () {return totalSize;} public void setTotalSize (long totalSize) {this.totalSize = totalSize;} public int getTotalPages () {return totalPages;} public void setTotalPages (int totalPages) {this.totalPages = totalPages } public List getContent () {return content;} public void setContent (List content) {this.content = content;}}
Create a new tool class PageUtils.java under the util directory
Package xxx.common.util;import com.github.pagehelper.PageInfo;import xxx.common.page.PageRequest;import xxx.common.page.PageResult / * @ author Zhiwei Wang * @ version $* @ name PageUtil * @ description * @ date 9:26 on 2022-1-19 * @ history * / public class PageUtils {/ * encapsulate the paging information into a unified interface * @ param pageRequest * @ param pageInfo * @ return * / public static PageResult getPageResult (PageRequest pageRequest, PageInfo pageInfo) {PageResult pageResult = new PageResult () PageResult.setPageNum (pageInfo.getPageNum ()); pageResult.setPageSize (pageInfo.getPageSize ()); pageResult.setTotalSize (pageInfo.getTotal ()); pageResult.setTotalPages (pageInfo.getPages ()); pageResult.setContent (pageInfo.getList ()); return pageResult;}}
Unified return body
Create a new Status.java under the common directory
Package xxx.common / * @ author Zhiwei Wang * @ version $* @ name Status * @ description return information enumeration * @ date 21:01 * @ history * / public enum Status {FAIL ("101l", "failed"), GET_FAIL ("111l", "query failed"), ADD_FAIL ("121l", "add failed"), DELETE_FAIL ("131"," delete failed ") UPDATE_FAIL, SUCCESS, GET_SUCCESS, ADD_SUCCESS, DELETE_SUCCESS, UPDATE_SUCCESS, modify successfully, ERROR USER_NOFOUND, ERROR_ACCOUNT, account or password error), USER_EXIST, USER_LOCK, account is locked Please contact administrator "), IP_LOCK (" 215,215 "," IP is locked, please contact administrator "), PARAM_ERROR (" 303 "," parameter error "), Token_Expired (" 1044 "," token Invalid expired ") Public String status; / / status code public String msg; / / prompt Status (String status, String msg) {this.status = status; this.msg = msg;}}
Create a new ReturnData.java under the common directory
Package xxx.common;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.serializer.SerializerFeature;/** * @ author Zhiwei Wang * @ version $* @ name ReturnData * @ description response data structure Encapsulation * @ date 20:59 on 2022-1-18 * @ history * / public class ReturnData {private String status; / / status code private String msg; / / prompt private T data / / data set public static ReturnData SUCCESS (T data) {return new ReturnData (Status.SUCCESS.status, Status.SUCCESS.msg, data);} public static ReturnData SUCCESS (String msg) {return new ReturnData (Status.SUCCESS.status, msg);} public static ReturnData SUCCESS () {return new ReturnData (Status.SUCCESS.status, Status.SUCCESS.msg) } public static ReturnData GET_SUCCESS (T data) {return new ReturnData (Status.GET_SUCCESS.status, Status.GET_SUCCESS.msg, data);} public static ReturnData GET_SUCCESS (String msg) {return new ReturnData (Status.GET_SUCCESS.status, msg);} public static ReturnData GET_SUCCESS () {return new ReturnData (Status.GET_SUCCESS.status, Status.GET_SUCCESS.msg) } public static ReturnData ADD_SUCCESS () {return new ReturnData (Status.ADD_SUCCESS.status, Status.ADD_SUCCESS.msg);} public static ReturnData ADD_SUCCESS (T data) {return new ReturnData (Status.ADD_SUCCESS.status, Status.ADD_SUCCESS.msg,data);} public static ReturnData DELETE_SUCCESS () {return new ReturnData (Status.DELETE_SUCCESS.status, Status.DELETE_SUCCESS.msg) } public static ReturnData UPDATE_SUCCESS () {return new ReturnData (Status.UPDATE_SUCCESS.status, Status.UPDATE_SUCCESS.msg);} public static ReturnData UPDATE_SUCCESS (T data) {return new ReturnData (Status.UPDATE_SUCCESS.status, Status.UPDATE_SUCCESS.msg,data);} public static ReturnData FAIL (String msg) {return new ReturnData (Status.FAIL.status, msg) } public static ReturnData FAIL () {return new ReturnData (Status.FAIL.status, Status.FAIL.msg);} public static ReturnData GET_FAIL (String msg) {return new ReturnData (Status.GET_FAIL.status, msg);} public static ReturnData GET_FAIL () {return new ReturnData (Status.GET_FAIL.status, Status.FAIL.msg) } public static ReturnData ADD_FAIL () {return new ReturnData (Status.ADD_FAIL.status, Status.ADD_FAIL.msg);} public static ReturnData DELETE_FAIL () {return new ReturnData (Status.DELETE_FAIL.status, Status.DELETE_FAIL.msg);} public static ReturnData UPDATE_FAIL () {return new ReturnData (Status.UPDATE_FAIL.status, Status.UPDATE_FAIL.msg) } public static ReturnData ERROR (String msg) {return new ReturnData (Status.ERROR.status, msg);} public static ReturnData ERROR () {return new ReturnData (Status.ERROR.status, Status.ERROR.msg);} public ReturnData (String status, String msg, T data) {this.status = status; this.msg = msg; this.data = data } public ReturnData (String status, String msg) {this.status = status; this.msg = msg;} public String getStatus () {return status;} public void setStatus (String status) {this.status = status;} public String getMsg () {return msg;} public void setMsg (String msg) {this.msg = msg } public T getData () {return data;} public void setData (T data) {this.data = data;} / * if the field is null, the field does not display * / @ Override public String toString () {return JSON.toJSONString (this) } / * returns all fields, including null * * @ return * / public String toAllString () {return JSON.toJSONString (this, SerializerFeature.WriteMapNullValue);}}
Swagger3 configuration
Create a new Swagger3Config.java under the common directory
Package xxx.common;import io.swagger.annotations.ApiOperation;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import springfox.documentation.builders.ApiInfoBuilder;import springfox.documentation.builders.PathSelectors;import springfox.documentation.builders.RequestHandlerSelectors;import springfox.documentation.service.ApiInfo;import springfox.documentation.service.Contact;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket / * @ author Zhiwei Wang * @ version $* @ name Swagger3Config * @ description * @ date 2022-1-18 21:40 * @ history * / @ Configurationpublic class Swagger3Config {@ Bean public Docket createRestApi () {return new Docket (DocumentationType.OAS_30) .apiInfo (apiInfo ()) .select () .apis (RequestHandlerSelectors.basePackage ("xxx.controller") ) .build (PathSelectors.any ()) .build () } private ApiInfo apiInfo () {return new ApiInfoBuilder () .title ("Swagger3 interface document") .description ("test API") .contact (new Contact ("test API", "http://localhost:8080/swagger-ui/index.html",") "1757895437@qq.com") .version ("1.0") .build () 2.2 template setup 2.2.1 install the idea plug-in: EasyCode
As shown in the figure, open the idea settings interface, select the plug-in, search for EasyCode, and click install.
2.2.2 setting template
As shown in the figure: open idea Settings-> other Settings-> EasyCode-MyBatisCodeHelper- > Template Setting
The template on the right is the template that generates the code. Paste the following template into it at once:
Entity
# # introducing macro definition $! define## uses macro definition to set callback (save location and file suffix) # save ("/ entity", ".java") # # use macro definition to set package suffix # setPackageSuffix ("entity") # # use global variables to implement default package import $! autoImportimport java.io.Serializable # # use macro definition to implement class annotation information # tableComment ("entity class") public class $! {tableInfo.name} implements Serializable {private static final long serialVersionUID = $! tool.serial (); # foreach ($column in $tableInfo.fullColumn) # if (${column.comment}) / * * ${column.comment} * / # end private $! {tool.getClsNameByFullName ($column.type)} $! {column.name} # end#foreach ($column in $tableInfo.fullColumn) # # implement the get,set method # getSetMethod ($column) # end @ Override public String toString () {return "$tableInfo.name {" + # foreach ($column in $tableInfo.fullColumn) "$column.name:" + $column.name + "," + # end'};}}
Dao
# # define initial variable # set ($tableName = $tool.append ($tableInfo.name, "Dao") # # set callback $! callback.setFileName ($tool.append ($tableName, ".java")) $! callback.setSavePath ($tool.append ($tableInfo.savePath, "/ dao")) # # get the primary key # if (! $tableInfo.pkColumn.isEmpty ()) # set ($Competition = $tableInfo.pkColumn.get (0)) # end#if ($tableInfo.savePackageName) package $! {tableInfo.savePackageName}. # {end} dao Import $! {tableInfo.savePackageName} .entity. $! {tableInfo.name}; import org.apache.ibatis.annotations.Param;import java.util.List;import java.util.Map / * $! {tableInfo.comment} ($! {tableInfo.name}) Table database access layer * * @ author $! author * @ since $! time.currTime () * / public interface $! {tableName} {/ * query single data through ID * * @ param $! pk.name primary key * @ return instance object * / $! {tableInfo .name} selectById ($! pk.shortType $! pk.name) / * paged query * * @ param start query start location * @ param limit query number * @ return object list * / List selectPage (@ Param ("start") int start, @ Param ("limit") int limit); / * * query all * * @ return object list * / List selectAll () / * query * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return object list * / List selectList ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * * New data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return influence rows * / int insert ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * batch add * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) s instance object collection * @ return influence rows * / int batchInsert (List $! tool.firstLowerCase ($! {tableInfo.name}) s) / * modify data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return influence rows * / int update ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * * delete data through primary key * * @ param $! pk.name primary key * @ return affect rows * / int deleteById ($! pk.shortType $! pk.name); / * * query total data * * @ total return data * / int count ();}
Service
# # define initial variable # set ($tableName = $tool.append ($tableInfo.name, "Service") # # set callback $! callback.setFileName ($tool.append ($tableName, ".java")) $! callback.setSavePath ($tool.append ($tableInfo.savePath, "/ service")) # # get the primary key # if (! $tableInfo.pkColumn.isEmpty ()) # set ($Competition = $tableInfo.pkColumn.get (0)) # end#if ($tableInfo.savePackageName) package $! {tableInfo.savePackageName}. # {end} service Import $! {tableInfo.savePackageName} .entity. $! {tableInfo.name}; import java.util.List;import java.util.Map;import $! {tableInfo.savePackageName} .common.page.PageResult / * $! {tableInfo.comment} ($! {tableInfo.name}) Table Service Interface * * @ author $! author * @ since $! time.currTime () * / public interface $! {tableName} {/ * query single data through ID * * @ param $! pk.name primary key * @ return instance object * / $! {tableInfo.name } selectById ($! pk.shortType $! pk.name) / * paged query * * @ param start query start position * @ param limit query number * @ return object list * / PageResult selectPage (int start, int limit) / * query all * * @ return object list * / List selectAll () / * query * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return object list * / List selectList ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * * New data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return influence rows * / int insert ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * batch add * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) s instance object collection * @ return influence rows * / int batchInsert (List $! tool.firstLowerCase ($! {tableInfo.name}) s) / * modify data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return modify * / $! {tableInfo.name} update ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) / * * delete data through primary key * * @ param $! pk.name primary key * @ return affect rows * / int deleteById ($! pk.shortType $! pk.name); / * * query total data * * @ total return data * / int count ();}
Serviceimpl
# # define initial variable # set ($tableName = $tool.append ($tableInfo.name, "ServiceImpl") # # set callback $! callback.setFileName ($tool.append ($tableName, ".java")) $! callback.setSavePath ($tool.append ($tableInfo.savePath) "/ service/impl") # # get the primary key # if (! $tableInfo.pkColumn.isEmpty ()) # set ($Competition = $tableInfo.pkColumn.get (0)) # end#if ($tableInfo.savePackageName) package $! {tableInfo.savePackageName}. # {end} service.impl Import $! {tableInfo.savePackageName} .entity. $! {tableInfo.name}; import $! {tableInfo.savePackageName} .dao. $! {tableInfo.name} Dao;import $! {tableInfo.savePackageName} .service. $! {tableInfo.name} Service;import org.springframework.stereotype.Service;import $! {tableInfo.savePackageName} .common.page.PageResult; import $! {tableInfo.savePackageName} .common.page.PageRequest; import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import $! {tableInfo.savePackageName} .common.util.PageUtils Import javax.annotation.Resource;import java.util.List;import java.util.Map / * $! {tableInfo.comment} ($! {tableInfo.name} table) Service implementation class * * @ author $! author * @ since $! time.currTime () * / @ Service ("$! tool.firstLowerCase ($! {tableInfo.name}) Service") public class $! {tableName} implements $! {tableInfo.name} Service {@ Resource private $! {tableInfo.name} Dao $! tool.firstLowerCase ($! {tableInfo.name}) Dao / * query single data through ID * * @ param $! pk.name primary key * @ return instance object * / @ Override public $! {tableInfo.name} selectById ($! pk.shortType $! pk.name) {return this.query! {tool.firstLowerCase ($! {tableInfo.name})} Dao.selectById ($! pk.name) } / * paged query * * @ param start query start location * @ param limit query list * / @ Override public PageResult selectPage (int start, int limit) {PageRequest pageRequest=new PageRequest (start,limit); return PageUtils.getPageResult (pageRequest, getPageInfo (pageRequest)) } / * call the paging plug-in to complete paging * @ param pageRequest * @ return * / private PageInfo getPageInfo (PageRequest pageRequest) {int pageNum = pageRequest.getPageNum (); int pageSize = pageRequest.getPageSize (); PageHelper.startPage (pageNum, pageSize) List $! {tool.firstLowerCase ($! {tableInfo.name})} s = this.steps! {tool.firstLowerCase ($! {tableInfo.name})} Dao.selectAll (); return new PageInfo ($! {tool.firstLowerCase ($! {tableInfo.name})} s) } / * query the collection of all * * @ return instance objects * / @ Override public List selectAll () {return this.objects! {tool.firstLowerCase ($! {tableInfo.name})} Dao.selectAll () } / * query the collection of return instance objects * / @ Override public List selectList ($! {tableInfo.name} $! {tool.firstLowerCase ($! {tableInfo.name})}) {return this.collection! {tool.firstLowerCase ($! {tableInfo.name})} Dao.selectList ($! {tool.firstLowerCase ($! {tableInfo.name})}) } / * New data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return instance object * / @ Override public int insert ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) {return this.object! {tool.firstLowerCase ($! {tableInfo.name}) } Dao.insert ($! tool.firstLowerCase ($! {tableInfo.name})) } / * batch addition of * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) s instance object collection * @ return effective number * / @ Override public int batchInsert (List $! tool.firstLowerCase ($! {tableInfo.name}) s) {return this.collection! {tool.firstLowerCase ($! {tableInfo.name})} Dao. BatchInsert ($! tool.firstLowerCase ($! {tableInfo.name}) s) } / * modify data * * @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object * @ return instance object * / @ Override public $! {tableInfo.name} update ($! {tableInfo.name} $! tool.firstLowerCase ($! {tableInfo.name})) {this.object! {tool.firstLowerCase ($! {tableInfo. Name})} Dao.update ($! tool.firstLowerCase ($! {tableInfo.name})) Return this.selectById ($! {tool.firstLowerCase ($! {tableInfo.name})} .get $! tool.firstUpperCase ($pk.name) ()) } / * delete data through primary key * * @ param $! is pk.name primary key * @ return successful * / @ Override public int deleteById ($! pk.shortType $! pk.name) {return this.delete! {tool.firstLowerCase ($! {tableInfo.name})} Dao.deleteById ($! pk.name) } / * Total data queried * * @ return Total data * / @ Override public int count () {return this.data! {tool.firstLowerCase ($! {tableInfo.name})} Dao.count ();}}
Controller
# # define initial variable # set ($tableName = $tool.append ($tableInfo.name, "Controller") # # set callback $! callback.setFileName ($tool.append ($tableName, ".java")) $! callback.setSavePath ($tool.append ($tableInfo.savePath, "/ controller")) # # get the primary key # if (! $tableInfo.pkColumn.isEmpty ()) # set ($Competition = $tableInfo.pkColumn.get (0)) # end#if ($tableInfo.savePackageName) package $! {tableInfo.savePackageName}. # {end} controller Import $! {tableInfo.savePackageName} .entity. $! {tableInfo.name}; import $! {tableInfo.savePackageName} .service. $! {tableInfo.name} Service;import org.springframework.web.bind.annotation.*;import $! {tableInfo.savePackageName} .common.ReturnData; import $! {tableInfo.savePackageName} .common.page.PageResult; import java.util.List;import javax.annotation.Resource / * $! {tableInfo.comment} ($! {tableInfo.name}) Control layer * * @ author $! author * @ since $! time.currTime () * / @ RestController@RequestMapping ("/ $! tool.firstLowerCase ($tableInfo.name)") public class $! {tableName} {/ * Service object * / @ Resource private $! {tableInfo.name} Service $! tool.firstLowerCase ($tableInfo.name) Service / * query single data through the primary key * * @ param $! tool.firstLowerCase ($tableInfo.name) parameter object * @ return single data * / @ RequestMapping (value = "get") Method = RequestMethod.GET) public ReturnData selectOne ($tableInfo.name $! tool.firstLowerCase ($tableInfo.name)) {$tableInfo.name result = $! {tool.firstLowerCase ($tableInfo.name)} Service.selectById ($! {tool.firstLowerCase ($tableInfo.name)} .getId ()) If (result! = null) {return ReturnData.GET_SUCCESS (result);} return ReturnData.GET_FAIL () } / * add a data * * @ param $! tool.firstLowerCase ($tableInfo.name) entity class * @ return Response object * / @ RequestMapping (value = "insert") Method = RequestMethod.POST) public ReturnData insert (@ RequestBody $tableInfo.name $! tool.firstLowerCase ($tableInfo.name)) {int result = $! {tool.firstLowerCase ($tableInfo.name)} Service.insert ($! tool.firstLowerCase ($tableInfo.name)) If (result > 0) {return ReturnData.ADD_SUCCESS ();} return ReturnData.ADD_FAIL () } / * modify a piece of data * * @ param $! tool.firstLowerCase ($tableInfo.name) entity class * @ return Response object * / @ RequestMapping (value = "update" Method = RequestMethod.PUT) public ReturnData update (@ RequestBody $tableInfo.name $! tool.firstLowerCase ($tableInfo.name)) {$tableInfo.name result = $! {tool.firstLowerCase ($tableInfo.name)} Service.update ($! tool.firstLowerCase ($tableInfo.name)) If (result! = null) {return ReturnData.UPDATE_SUCCESS (result);} return ReturnData.UPDATE_FAIL () } / * Delete a piece of data * * @ param $! tool.firstLowerCase ($tableInfo.name) Parameter object * @ return Response object * / @ RequestMapping (value = "delete" Method = RequestMethod.DELETE) public ReturnData delete ($tableInfo.name $! tool.firstLowerCase ($tableInfo.name)) {int result = $! {tool.firstLowerCase ($tableInfo.name)} Service.deleteById ($! {tool.firstLowerCase ($tableInfo.name)} .getId ()) If (result > 0) {return ReturnData.DELETE_SUCCESS ();} return ReturnData.DELETE_FAIL () } / * query all * * @ return Response objects * / @ RequestMapping (value = "selectAll", method = RequestMethod.GET) public ReturnData selectAll () {List $! tool.firstLowerCase ($tableInfo.name) s = $! {tool.firstLowerCase ($tableInfo.name)} Service.selectAll () If ($! tool.firstLowerCase ($tableInfo.name) s! = null) {return ReturnData.GET_SUCCESS ($! tool.firstLowerCase ($tableInfo.name) s);} return ReturnData.GET_FAIL () } / * paging query * * @ param start offset * @ param limit number * @ return Response object * / @ RequestMapping (value = "selectPage", method = RequestMethod.GET) public ReturnData selectPage (Integer start, Integer limit) {PageResult pageResult = $! {tool.firstLowerCase ($tableInfo.name)} Service.selectPage (start, limit) If (pageResult! = null) {return ReturnData.GET_SUCCESS (pageResult);} return ReturnData.GET_FAIL ();}}
Mapper.xml
# # introducing mybatis supports $! mybatisSupport## setting save name and location $! callback.setFileName ($tool.append ($! {tableInfo.name}, "Dao.xml")) $! callback.setSavePath ($tool.append ($modulePath) "/ src/main/resources/mapper") # # get the primary key # if (! $tableInfo.pkColumn.isEmpty ()) # set ($Competition = $tableInfo.pkColumn.get (0)) # end # foreach ($column in $tableInfo.fullColumn) # end # allSqlColumn () select from $! tableInfo.obj.name where $! competition .obj.name = # {$! pk.name} select from $! tableInfo.obj.name limit # {start} # {limit} select from $! tableInfo.obj.name select from $! tableInfo.obj.name # foreach ($column in $tableInfo.fullColumn) and $! column.obj.name = # {$! column.name} # end Insert into $! {tableInfo.obj.name} (# foreach ($column in $tableInfo.fullColumn) $! column.obj.name#if ($velocityHasNext) # end#end) values (# foreach ($column in $tableInfo.fullColumn) # {$! {column.name}} # if ($velocityHasNext), # end#end) insert into $! {tableInfo.obj.name} (# foreach ($column in $tableInfo.fullColumn) $! column.obj.name#if ($velocityHasNext) # end#end) values (# foreach ($column in $tableInfo.fullColumn) # {item.items! {column.name}} # if ($velocityHasNext) # end#end) update $! {tableInfo.obj.parent.name}. $! {tableInfo.obj.name} # foreach ($column in $tableInfo.otherColumn) $! column.obj.name = # {$! column.name} # end where $! pk.obj.name = # {$! pk.name} delete from $! {tableInfo.obj.name} where $! pk.obj.name = # {$! pk.name} select count (*) from $! {tableInfo.obj.name} 2.3.Generation method
First, use idea to connect to the database, which is omitted here. If you don't know how to connect, please refer to: mysql connection idea detailed tutorial
As shown in the figure, select the table to generate code-> right-click-> EasyCodeMybatisCodeHelper- > Generate_Code, and the following window pops up
Module: select which module to generate into
Package: fill in your package name
Path: project path
Select the class to be generated and click ok to see that the corresponding class has been generated in the project.
Note: using mybatis requires comments in the startup class
/ / scan the path configuration of dao @ MapperScan (".dao") Thank you for reading! This is the end of this article on "how to use EasyCode to generate springboot+mybatis basic programs". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.