一款基于界面配置的代码生成工具。与其他开源项目的不同点是,只生成了后端代码,无论是前后端分离项目还是不分离项目,都可以轻松的接入。同时,封装了大量的基础性代码,极大地简化了开发过程。
Maven引用(点击 https://search.maven.org/search?q=g:io.github.xiaoyudeguang 查看最新版本)
io.github.xiaoyudeguang
easy-web
3.1.8-RELREASE
配置数据源(在application.properties文件中配置)
#datasource config
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://数据库ip地址:3306/数据库名?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username=账号
spring.datasource.password=密码
生成代码
方式一:可视化生成代码(访问 http://localhost:8080/easy-code )
方式二:通过@Configuration 和 @Bean注解注入
@Configuration
public class BeanConfiguration {
@Bean
public AbstractGenerator getBean1() {
return new AbstractGenerator() {
@Override
public void afterPropertiesSet() throws Exception {
this.tableName = "db_person";
this.entityName = "Person";
this.packageName = "com.zlyx.easytest.test";
... 其他配置(以上三项是每次必须配置的选项)...
}
};
}
@Bean
public AbstractGenerator getBean2() {
return new AbstractGenerator() {
@Override
public void afterPropertiesSet() throws Exception {
this.tableName = "db_dept";
this.entityName = "Dept";
this.packageName = "com.zlyx.easytest.test";
... 其他配置(以上三项是每次必须配置的选项)...
}
}.close();
}
}
如果你想让这个Bean失效,只需要在return前调用AbstractGenerator对象的close()方法即可(第二个Bean对象例子)。
好了,到这里,如果你的springboot程序是热加载方式运行中的,选中你的项目刷新一下,应该就可以看到生成的代码了。如果还没启动呢,那就启动一下呗。之后,即使你不删除EasyGenerator类,也不会覆盖你已经生成的代码。
easy-web默认引用了easy-log(项目地址:https://gitee.com/xiaoyudeguang/easy-log)。
easy-web默认引用了easy-mybatis(项目地址:https://gitee.com/xiaoyudeguang/easy-mybatis)
## 生成代码效果:
#### Controller类
package com.zlyx.easytest.test.controller;
import com.zlyx.easyswagger.annotations.SpringMapping;
import com.zlyx.easyswagger.annotations.SpringController;
import com.zlyx.easyweb.web.controller.AbstractController;
import com.zlyx.easytest.test.service.PersonService;
import com.zlyx.easytest.test.entity.Person;
/**
* 前端控制器
* @author easy-web [email protected]
* @date 2019-01-06
*/
@SpringController(value = {"/person"}, todo = {"前端控制器"})
public class PersonController extends AbstractController {
@SpringMapping(value = {"/demo"}, todo = {"easy-web示例方法"}, notes = "easy-web示例方法简介")
public String demoMethod(){
return null;
}
}
#### Service接口
package com.zlyx.easytest.test.service;
import com.zlyx.easytest.test.entity.Person;
import com.zlyx.easytest.test.mapper.PersonMapper;
import com.zlyx.easyweb.web.service.AbstractService;
/**
* 服务类
* @author easy-web [email protected]
* @Date 2019-01-06
*/
public interface PersonService extends AbstractService {
}
#### Service实现类
package com.zlyx.easytest.test.service.impl;
import com.zlyx.easytest.test.entity.Person;
import com.zlyx.easytest.test.mapper.PersonMapper;
import com.zlyx.easytest.test.service.PersonService;
import com.zlyx.easyweb.web.service.impl.AbstractServiceImpl;
import com.zlyx.easyweb.annotations.SpringService;
/**
* 服务实现类
* @author easy-web [email protected]
* @since 2019-01-06
*/
@SpringService(todo = "服务实现类")
public class PersonServiceImpl extends AbstractServiceImpl implements PersonService {
}
#### Mapper接口
package com.zlyx.easytest.test.mapper;
import org.apache.ibatis.annotations.Mapper;
import com.zlyx.easytest.test.entity.Person;
import com.zlyx.easyweb.web.mapper.AbstractMapper;
/**
* Mapper接口
* @author easy-web [email protected]
* @since 2019-01-06
*/
@Mapper
public interface PersonMapper extends AbstractMapper {
}
#### Entity类
package com.zlyx.easytest.test.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import java.io.Serializable;
import com.zlyx.easyweb.annotations.TableBean;
/**
*
* @author easy-web [email protected]
* @since 2019-01-06
*/
@TableBean(value = "test_person", todo = {"test_person实体类"})
@TableName("test_person")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(value = "person_id", type = IdType.AUTO)
private Long personId;
...其他属性略...
}