全流程代码生成器full-code-generator,自动生成controller层、service层、service impl层、dao层、entity及mapper层所有代码。实现了单表的增删改查及分页,格式校验,并集成swagger实现api文档。让你不再为繁琐的注释和简单的接口实现而烦恼,期望得到你的star,thank you very much.
https://github.com/fanlinglong/full-code-generator
https://gitee.com/fanlinglong/full-code-generator
MAVEN坐标
<!-- https://mvnrepository.com/artifact/tech.fanlinglong.common/full-code-generator -->
<dependency>
<groupId>tech.fanlinglong.common</groupId>
<artifactId>full-code-generator</artifactId>
<version>1.0.0</version>
</dependency>
数据表结构样式
CREATE TABLE `author` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`user_id` bigint(20) DEFAULT NULL COMMENT '用户ID',
`invite_code` varchar(20) DEFAULT NULL COMMENT '邀请码',
`pen_name` varchar(20) DEFAULT NULL COMMENT '笔名',
`tel_phone` varchar(20) DEFAULT NULL COMMENT '手机号码',
`chat_account` varchar(50) DEFAULT NULL COMMENT 'QQ或微信账号',
`email` varchar(50) DEFAULT NULL COMMENT '电子邮箱',
`work_direction` tinyint(4) DEFAULT NULL COMMENT '作品方向,0:男频,1:女频',
`status` tinyint(4) DEFAULT '0' COMMENT '0:正常,1:封禁',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COMMENT='作者表';
要求必须有表注释,要求必须有主键为id,所有字段必须有注释(便于生成java注释swagger等)。
用法
/**
* 生成源代码
*/
public class TestMain {
//基础信息
public static final String PROJECT = "cloud";
public static final String AUTHOR = "fanll";
public static final String VERSION = "V1.0";
//数据库连接信息
public static final String URL = "jdbc:mysql://127.0.0.1:3306/novel_cloud?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
public static final String NAME = "root";
public static final String PASSWORD = "123456";
public static final String DATABASE = "novel_cloud";
//类信息
public static final String TABLE = "author";
public static final String CLASS_NAME = "author";
public static final String CLASS_COMMENT = "作者表";
public static final String TIME = "2021年10月25日";
public static final String AGILE = new Date().getTime() + "";
//路径信息
public static final String ENTITY_URL = "tech.fanll.cloud.demo.entity";
public static final String DAO_URL = "tech.fanll.cloud.demo.dao";
public static final String DAO_IMPL_URL = "mappers";
public static final String SERVICE_URL = "tech.fanll.cloud.demo.service";
public static final String SERVICE_IMPL_URL = "tech.fanll.cloud.demo.service.impl";
public static final String CONTROLLER_URL = "tech.fanll.cloud.demo.controller";
public static void main(String[] args) {
BasisInfo bi = new BasisInfo(PROJECT, AUTHOR, VERSION, URL, NAME, PASSWORD, DATABASE, TIME,
AGILE, ENTITY_URL, DAO_URL, DAO_IMPL_URL, SERVICE_URL, SERVICE_IMPL_URL, CONTROLLER_URL);
bi.setTable(TABLE);
bi.setEntityName(MySqlToJavaUtil.getClassName(TABLE));
bi.setObjectName(MySqlToJavaUtil.changeToJavaFiled(TABLE));
bi.setEntityComment(CLASS_COMMENT);
try {
bi = EntityInfoUtil.getInfo(bi);
String aa1 = Generator.createEntity("D:\\fanll\\cloud\\", bi).toString();
String aa2 = Generator.createDao("D:\\fanll\\cloud\\", bi).toString();
String aa3 = Generator.createDaoImpl("D:\\fanll\\cloud\\", bi).toString();
String aa4 = Generator.createService("D:\\fanll\\cloud\\", bi).toString();
String aa5 = Generator.createServiceImpl("D:\\fanll\\cloud\\", bi).toString();
String aa6 = Generator.createController("D:\\fanll\\cloud\\", bi).toString();
System.out.println(aa1);
System.out.println(aa2);
System.out.println(aa3);
System.out.println(aa4);
System.out.println(aa5);
System.out.println(aa6);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
生成代码
生成的实体类
/**
* @filename:Author 2021年10月25日
* @project cloud V1.0
* Copyright(c) 2021 fanll Co. Ltd.
* All right reserved.
*/
package tech.fanll.cloud.demo.entity;
import java.io.Serializable;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
/**
*
* @Description: 作者表
* @Author: fanll
* @CreateDate: 2021年10月25日
* @Version: V1.0
*
*/
public class Author implements Serializable {
private static final long serialVersionUID = 1635170883186L;
@ApiModelProperty(name = "id" , value = "主键")
private Long id;
@ApiModelProperty(name = "userId" , value = "用户ID")
private Long userId;
@ApiModelProperty(name = "inviteCode" , value = "邀请码")
private String inviteCode;
@ApiModelProperty(name = "penName" , value = "笔名")
private String penName;
@ApiModelProperty(name = "telPhone" , value = "手机号码")
private String telPhone;
@ApiModelProperty(name = "chatAccount" , value = "QQ或微信账号")
private String chatAccount;
@ApiModelProperty(name = "email" , value = "电子邮箱")
private String email;
@ApiModelProperty(name = "workDirection" , value = "作品方向,0:男频,1:女频")
private Integer workDirection;
@ApiModelProperty(name = "status" , value = "0:正常,1:封禁")
private Integer status;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@ApiModelProperty(name = "createTime" , value = "创建时间")
private Date createTime;
public Long setId(Long id) {
this.id = id;
return this;
}
public Long getId() {
return this.id;
}
public Long setUserId(Long userId) {
this.userId = userId;
return this;
}
public Long getUserId() {
return this.userId;
}
public String setInviteCode(String inviteCode) {
this.inviteCode = inviteCode == null ? null : inviteCode.trim();
if ("".equals(this.inviteCode)){
this.inviteCode = null;
}
return this;
}
public String getInviteCode() {
return this.inviteCode;
}
public String setPenName(String penName) {
this.penName = penName == null ? null : penName.trim();
if ("".equals(this.penName)){
this.penName = null;
}
return this;
}
public String getPenName() {
return this.penName;
}
public String setTelPhone(String telPhone) {
this.telPhone = telPhone == null ? null : telPhone.trim();
if ("".equals(this.telPhone)){
this.telPhone = null;
}
return this;
}
public String getTelPhone() {
return this.telPhone;
}
public String setChatAccount(String chatAccount) {
this.chatAccount = chatAccount == null ? null : chatAccount.trim();
if ("".equals(this.chatAccount)){
this.chatAccount = null;
}
return this;
}
public String getChatAccount() {
return this.chatAccount;
}
public String setEmail(String email) {
this.email = email == null ? null : email.trim();
if ("".equals(this.email)){
this.email = null;
}
return this;
}
public String getEmail() {
return this.email;
}
public Integer setWorkDirection(Integer workDirection) {
this.workDirection = workDirection;
return this;
}
public Integer getWorkDirection() {
return this.workDirection;
}
public Integer setStatus(Integer status) {
this.status = status;
return this;
}
public Integer getStatus() {
return this.status;
}
public Date setCreateTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Date getCreateTime() {
return this.createTime;
}
}
生成的DAO
/**
* @filename:AuthorDao 2021年10月25日
* @project cloud V1.0
* Copyright(c) 2021 fanll Co. Ltd.
* All right reserved.
*/
package tech.fanll.cloud.demo.dao;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import tech.fanll.cloud.demo.entity.Author;
/**
*
* @Description: 作者表——DAO
* @Author: fanll
* @CreateDate: 2021年10月25日
* @Version: V1.0
*
*/
@Mapper
public interface AuthorDao {
Author selectByPrimaryKey(Long id);
int deleteByPrimaryKey(Long id);
int insertSelective(Author author);
int updateByPrimaryKeySelective(Author author);
List<Author> queryAuthorList(Author author);
}
生成的XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="tech.fanll.cloud.demo.dao.AuthorDao">
<resultMap id="BaseResultMap" type="tech.fanll.cloud.demo.entity.Author">
<id column="id" jdbcType="BIGINT" property="id" />
<id column="user_id" jdbcType="BIGINT" property="userId" />
<id column="invite_code" jdbcType="VARCHAR" property="inviteCode" />
<id column="pen_name" jdbcType="VARCHAR" property="penName" />
<id column="tel_phone" jdbcType="VARCHAR" property="telPhone" />
<id column="chat_account" jdbcType="VARCHAR" property="chatAccount" />
<id column="email" jdbcType="VARCHAR" property="email" />
<id column="work_direction" jdbcType="TINYINT" property="workDirection" />
<id column="status" jdbcType="TINYINT" property="status" />
<id column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Base_Column_List">
id, user_id, invite_code, pen_name, tel_phone, chat_account, email, work_direction, status, create_time
</sql>
<!-- 查询 -->
<select id="selectByPrimaryKey" parameterType="java.lang.Long"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from author
where id = #{id,jdbcType=BIGINT}
</select>
<!-- 删除 -->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from author
where id = #{id,jdbcType=BIGINT}
</delete>
<!-- 选择添加 -->
<insert id="insertSelective" parameterType="tech.fanll.cloud.demo.entity.Author">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into author
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="userId != null">
user_id,
</if>
<if test="inviteCode != null and inviteCode.trim() !='' ">
invite_code,
</if>
<if test="penName != null and penName.trim() !='' ">
pen_name,
</if>
<if test="telPhone != null and telPhone.trim() !='' ">
tel_phone,
</if>
<if test="chatAccount != null and chatAccount.trim() !='' ">
chat_account,
</if>
<if test="email != null and email.trim() !='' ">
email,
</if>
<if test="workDirection != null">
work_direction,
</if>
<if test="status != null">
status,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="userId != null">
#{userId,jdbcType=BIGINT},
</if>
<if test="inviteCode != null and inviteCode.trim() !='' ">
#{inviteCode,jdbcType=VARCHAR},
</if>
<if test="penName != null and penName.trim() !='' ">
#{penName,jdbcType=VARCHAR},
</if>
<if test="telPhone != null and telPhone.trim() !='' ">
#{telPhone,jdbcType=VARCHAR},
</if>
<if test="chatAccount != null and chatAccount.trim() !='' ">
#{chatAccount,jdbcType=VARCHAR},
</if>
<if test="email != null and email.trim() !='' ">
#{email,jdbcType=VARCHAR},
</if>
<if test="workDirection != null">
#{workDirection,jdbcType=TINYINT},
</if>
<if test="status != null">
#{status,jdbcType=TINYINT},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<!-- 选择修改 -->
<update id="updateByPrimaryKeySelective" parameterType="tech.fanll.cloud.demo.entity.Author">
update author
<set>
<if test="id != null">
id = #{id,jdbcType=BIGINT},
</if>
<if test="userId != null">
user_id = #{userId,jdbcType=BIGINT},
</if>
<if test="inviteCode != null and inviteCode.trim() !='' ">
invite_code = #{inviteCode,jdbcType=VARCHAR},
</if>
<if test="penName != null and penName.trim() !='' ">
pen_name = #{penName,jdbcType=VARCHAR},
</if>
<if test="telPhone != null and telPhone.trim() !='' ">
tel_phone = #{telPhone,jdbcType=VARCHAR},
</if>
<if test="chatAccount != null and chatAccount.trim() !='' ">
chat_account = #{chatAccount,jdbcType=VARCHAR},
</if>
<if test="email != null and email.trim() !='' ">
email = #{email,jdbcType=VARCHAR},
</if>
<if test="workDirection != null">
work_direction = #{workDirection,jdbcType=TINYINT},
</if>
<if test="status != null">
status = #{status,jdbcType=TINYINT},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=bigint}
</update>
<!-- 组合条件查询 -->
<select id="queryAuthorList" parameterType="tech.fanll.cloud.demo.entity.Author"
resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from author
<where>
<if test="id != null">
id = #{id,jdbcType=BIGINT}
</if>
<if test="userId != null">
AND user_id = #{userId ,jdbcType=BIGINT}
</if>
<if test="inviteCode != null and inviteCode.trim() !='' ">
AND invite_code = #{inviteCode ,jdbcType=VARCHAR}
</if>
<if test="penName != null and penName.trim() !='' ">
AND pen_name = #{penName ,jdbcType=VARCHAR}
</if>
<if test="telPhone != null and telPhone.trim() !='' ">
AND tel_phone = #{telPhone ,jdbcType=VARCHAR}
</if>
<if test="chatAccount != null and chatAccount.trim() !='' ">
AND chat_account = #{chatAccount ,jdbcType=VARCHAR}
</if>
<if test="email != null and email.trim() !='' ">
AND email = #{email ,jdbcType=VARCHAR}
</if>
<if test="workDirection != null">
AND work_direction = #{workDirection ,jdbcType=TINYINT}
</if>
<if test="status != null">
AND status = #{status ,jdbcType=TINYINT}
</if>
<if test="createTime != null">
AND create_time = #{createTime ,jdbcType=TIMESTAMP}
</if>
</where>
</select>
</mapper>
生成的SERVICE
/**
* @filename:AuthorService 2021年10月25日
* @project cloud V1.0
* Copyright(c) 2021 fanll Co. Ltd.
* All right reserved.
*/
package tech.fanll.cloud.demo.service;
import java.util.List;
import com.github.pagehelper.PageInfo;
import com.github.gencode.bean.AppPage;
import tech.fanll.cloud.demo.entity.Author;
/**
*
* @Description: 作者表——SERVICE
* @Author: fanll
* @CreateDate: 2021年10月25日
* @Version: V1.0
*
*/
public interface AuthorService {
/**
* @explain 查询作者表对象
* @param id:对象参数
* @return Author
* @author fanll
*/
Author selectByPrimaryKey(Long id);
/**
* @explain 删除作者表对象
* @param id:对象参数
* @return int
* @author fanll
*/
int deleteByPrimaryKey(Long id);
/**
* @explain 添加作者表对象
* @param Author:对象参数
* @return int
* @author fanll
*/
int insertSelective(Author author);
/**
* @explain 修改作者表对象
* @param Author:对象参数
* @return int
* @author fanll
*/
int updateByPrimaryKeySelective(Author author);
/**
* @explain 查询作者表集合
* @param Author:对象参数
* @return List<Author>
* @author fanll
*/
List<Author> queryAuthorList(Author author);
/**
* @explain 分页查询作者表
* @param Author:对象参数
* @return PageInfo<Author>
* @author fanll
*/
PageInfo<Author> getAuthorBySearch(AppPage<Author> page);
}
生成的SERVICE_IMPL
/**
* @filename:AuthorServiceImpl 2021年10月25日
* @project cloud V1.0
* Copyright(c) 2021 fanll Co. Ltd.
* All right reserved.
*/
package tech.fanll.cloud.demo.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.gencode.bean.AppPage;
import tech.fanll.cloud.demo.entity.Author;
import tech.fanll.cloud.demo.dao.AuthorDao;
import tech.fanll.cloud.demo.service.AuthorService;
/**
*
* @Description: 作者表——SERVICE_IMPL
* @Author: fanll
* @CreateDate: 2021年10月25日
* @Version: V1.0
*
*/
@Service
public class AuthorServiceImpl implements AuthorService {
Logger logger = LoggerFactory.getLogger(this.getClass());
// 构造注入
public AuthorServiceImpl(AuthorDao authorDao){
this.authorDao = authorDao;
}
public AuthorDao authorDao;
//查询对象
@Override
public Author selectByPrimaryKey(Long id) {
return authorDao.selectByPrimaryKey(id);
}
//删除对象
@Override
public int deleteByPrimaryKey(Long id) {
return authorDao.deleteByPrimaryKey(id);
}
//添加对象
@Override
public int insertSelective(Author author) {
return authorDao.insertSelective(author);
}
//修改对象
@Override
public int updateByPrimaryKeySelective(Author author) {
return authorDao.updateByPrimaryKeySelective(author);
}
//查询集合
@Override
public List<Author> queryAuthorList(Author author) {
return authorDao.queryAuthorList(author);
}
//分页查询
@Override
public PageInfo<Author> getAuthorBySearch(AppPage<Author> page) {
// TODO Auto-generated method stub
PageHelper.startPage(page.getPageNum(),page.getPageSize());
List<Author> list=authorDao.queryAuthorList(page.getParam());
PageInfo<Author> pageInfo = new PageInfo<Author>(list);
return pageInfo;
}
}
生成的CONTROLLER,父类实现了增删改查接口,分页查询
/**
* @filename:AuthorController 2021年10月25日
* @project cloud V1.0
* Copyright(c) 2021 fanll Co. Ltd.
* All right reserved.
*/
package tech.fanll.cloud.demo.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageInfo;
import com.github.gencode.bean.AppPage;
import com.github.gencode.bean.JsonResult;
import tech.fanll.cloud.demo.entity.Author;
import tech.fanll.cloud.demo.service.AuthorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
/**
*
* @Description: 作者表接口层
* @Author: fanll
* @CreateDate: 2021年10月25日
* @Version: V1.0
*
*/
@Api(description = "作者表",value="作者表" )
@RestController
@RequestMapping("/author")
public class AuthorController {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
public AuthorService authorServiceImpl;
/**
* @explain 查询作者表对象 <swagger GET请求>
* @param id:对象参数
* @return author
* @author fanll
* @time 2021年10月25日
*/
@GetMapping("/getAuthorById/{id}")
@ApiOperation(value = "获取作者表信息", notes = "获取作者表信息[author],作者:fanll")
@ApiImplicitParam(paramType="path", name = "id", value = "作者表id", required = true, dataType = "Long")
public JsonResult<Author> getAuthorById(@PathVariable("id")Long id){
JsonResult<Author> result=new JsonResult<Author>();
try {
Author author=authorServiceImpl.selectByPrimaryKey(id);
if (author!=null) {
result.setCode(1);
result.setMessage("成功");
result.setData(author);
} else {
logger.error("获取作者表失败ID:"+id);
result.setCode(-1);
result.setMessage("你获取的作者表不存在");
}
} catch (Exception e) {
logger.error("获取作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
/**
* @explain 添加作者表对象
* @param author:对象参数
* @return int
* @author fanll
* @time 2021年10月25日
*/
@PostMapping("/insertSelective")
@ApiOperation(value = "添加作者表", notes = "添加作者表[author],作者:fanll")
public JsonResult<Author> insertSelective(Author author){
JsonResult<Author> result=new JsonResult<Author>();
try {
int rg=authorServiceImpl.insertSelective(author);
if (rg>0) {
result.setCode(1);
result.setMessage("成功");
result.setData(author);
} else {
logger.error("添加作者表执行失败:"+author.toString());
result.setCode(-1);
result.setMessage("执行失败,请稍后重试");
}
} catch (Exception e) {
logger.error("添加作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
/**
* @explain 删除作者表对象
* @param id:对象参数
* @return int
* @author fanll
* @time 2021年10月25日
*/
@PostMapping("/deleteByPrimaryKey")
@ApiOperation(value = "删除作者表", notes = "删除作者表,作者:fanll")
@ApiImplicitParam(paramType="query", name = "id", value = "作者表id", required = true, dataType = "Long")
public JsonResult<Object> deleteByPrimaryKey(Long id){
JsonResult<Object> result=new JsonResult<Object>();
try {
int reg=authorServiceImpl.deleteByPrimaryKey(id);
if (reg>0) {
result.setCode(1);
result.setMessage("成功");
result.setData(id);
} else {
logger.error("删除作者表失败ID:"+id);
result.setCode(-1);
result.setMessage("执行错误,请稍后重试");
}
} catch (Exception e) {
logger.error("删除作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
/**
* @explain 修改作者表对象
* @param author:对象参数
* @return author
* @author fanll
* @time 2021年10月25日
*/
@ApiOperation(value = "修改作者表", notes = "修改作者表[author],作者:fanll")
@PostMapping("/updateByPrimaryKeySelective")
public JsonResult<Author> updateByPrimaryKeySelective(Author author){
JsonResult<Author> result=new JsonResult<Author>();
try {
int reg = authorServiceImpl.updateByPrimaryKeySelective(author);
if (reg>0) {
result.setCode(1);
result.setMessage("成功");
result.setData(author);
} else {
logger.error("修改作者表失败ID:"+author.toString());
result.setCode(-1);
result.setMessage("执行错误,请稍后重试");
}
} catch (Exception e) {
logger.error("修改作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
/**
* @explain 获取匹配作者表
* @param author:对象参数
* @return List<Author>
* @author fanll
* @time 2021年10月25日
*/
@ApiOperation(value = "条件查询作者表", notes = "条件查询[author],作者:fanll")
@PostMapping("/queryAuthorList")
public JsonResult<List<Author>> queryAuthorList(Author author){
JsonResult<List<Author>> result=new JsonResult<List<Author>>();
try {
List<Author> list = authorServiceImpl.queryAuthorList(author);
result.setCode(1);
result.setMessage("成功");
result.setData(list);
} catch (Exception e) {
logger.error("获取作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
/**
* @explain 分页条件查询作者表
* @param AppPage<Author>:分页参数
* @param Author:对象参数
* @return PageInfo<Author>
* @author fanll
* @time 2021年10月25日
*/
@GetMapping("/getPageAuthor")
@ApiOperation(value = "分页查询", notes = "分页查询返回对象[PageInfo<Author>],作者:边鹏")
@ApiImplicitParams({
@ApiImplicitParam(paramType="query", name = "pageNum", value = "当前页", required = true, dataType = "int"),
@ApiImplicitParam(paramType="query", name = "pageSize", value = "页行数", required = true, dataType = "int")
})
public JsonResult<PageInfo<Author>> getAuthorBySearch(AppPage<Author> page, Author author){
JsonResult<PageInfo<Author>> result=new JsonResult<PageInfo<Author>>();
//其他参数
page.setParam(author);
//分页数据
try {
PageInfo<Author> pageInfo = authorServiceImpl.getAuthorBySearch(page);
result.setCode(1);
result.setMessage("成功");
result.setData(pageInfo);
} catch (Exception e) {
logger.error("分页查询作者表执行异常:"+e.getMessage());
result.setCode(-1);
result.setMessage("执行异常,请稍后重试");
}
return result;
}
}
看到这里,大家应该能看出,这个代码生成只适合一些特定的项目,不过确实为了那些喜欢lombok,swagger的猿们减少了很多不必要的工作。 一些朋友在问我JsonResult类,都在包内部。
评论区