自动生成代码service层代码

 
 
  • GeneratorService 控制层接口
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 
 * @Time 
 * @description
 * 
 */
@Service
public interface GeneratorService {
   List<Map<String, Object>> list();

   byte[] generatorCode(String[] tableNames);
}
 
 
 
 
  • GeneratorServiceImpl 控制层接口实现类
import com.alibaba.dubbo.config.annotation.Service;
import com.zscat.shop.dao.GeneratorMapper;
import com.zscat.shop.service.GeneratorService;
import com.zscat.shop.utils.GenUtils;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;


@Service(version = "1.0.0",retries = 0,timeout = 60000)
public class GeneratorServiceImpl implements GeneratorService {
	@Autowired
	GeneratorMapper generatorMapper;
        //此方法是为了放页面查询到当前数据库的所有表,可以在网页上查看到
	@Override
	public List<Map<String, Object>> list() {
		List<Map<String, Object>> list = generatorMapper.list();
		return list;
	}
  
	@Override
	public byte[] generatorCode(String[] tableNames) {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();   //字节输出流
		ZipOutputStream zip = new ZipOutputStream(outputStream);      //定义压缩包输出流,需要基础流
		for(String tableName : tableNames){
			//查询表信息
			Map<String, String> table = generatorMapper.get(tableName);
			//查询列信息
			List<Map<String, String>> columns = generatorMapper.listColumns(tableName);
			//生成代码
			GenUtils.generatorCode(table, columns, zip);
		}
		IOUtils.closeQuietly(zip);
		return outputStream.toByteArray();
	}

}

IOUtils    org.apache.commons.io;  包里的工具类

工具类后面有  GenUtils 

猜你喜欢

转载自blog.csdn.net/qq_40680190/article/details/79963885