项目导入初始化

This commit is contained in:
暮光:城中城
2018-11-27 22:19:16 +08:00
parent 9350e107f2
commit f3d2b4eeab
189 changed files with 16210 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package com.zyplayer.doc.manage;
import java.net.InetAddress;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
/**
* 程序启动器
*/
@SpringBootApplication
@MapperScan("com.zyplayer.doc.manage.repository")
public class Application extends SpringBootServletInitializer {
private static Logger logger = LoggerFactory.getLogger(Application.class);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext application = SpringApplication.run(Application.class, args);
Environment env = application.getEnvironment();
logger.info("\n----------------------------------------------------------\n\t" +
"\t\t地址列表\n\t"+
"文档地址http://{}:{}/document.html\n"+
"----------------------------------------------------------",
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")
);
}
}

View File

@@ -0,0 +1,60 @@
package com.zyplayer.doc.manage.framework.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.mg.swagger.framework.service.MgStorageService;
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
/**
* 申明为@Service之后网页上才能使用存储能力同时需要在@EnableSwagger2的地方添加@EnableSwaggerMgUi注解
* 才能开启存储的接口<br/>
* 开放存储能力的好处:<br/>
* 所有网页的配置、调试值都可以存储到服务器的数据库中,便于团队所有人的调试,一人配置,所有人受益<br/>
* 如果不开启的话数据是存放在浏览器的localStorage中每个人、每个浏览器都得配置一次才能使用<br/>
*
* @author 暮光:城中城
* @since 2018年8月19日
*/
@Service
public class MgStorageServiceImpl implements MgStorageService {
@Autowired
ZyplayerStorageService zyplayerStorageService;
/**
* 使用数据库来存储,例: storageMapper.select(key);
*/
@Override
public String get(String key) {
QueryWrapper<ZyplayerStorage> wrapper = new QueryWrapper<>();
wrapper.eq(true, "doc_key", key);
ZyplayerStorage zyplayerStorage = zyplayerStorageService.getOne(wrapper);
if (zyplayerStorage == null) {
return null;
}
return zyplayerStorage.getDocValue();
}
/**
* 使用数据库来存储,例: storageMapper.updateOrInsert(key, value);
*/
@Override
public void put(String key, String value) {
ZyplayerStorage entity = new ZyplayerStorage();
entity.setDocValue(value);
UpdateWrapper<ZyplayerStorage> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq(true, "doc_key", key);
boolean update = zyplayerStorageService.update(entity, updateWrapper);
if (!update) {
entity = new ZyplayerStorage();
entity.setDocValue(value);
entity.setDocKey(key);
zyplayerStorageService.save(entity);
}
}
}

View File

@@ -0,0 +1,22 @@
package com.zyplayer.doc.manage.framework.config;
import org.springframework.context.annotation.Configuration;
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
/**
* 不需要管理本项目的文档,只需要开启@EnableSwaggerMgUi即可
* @author 暮光:城中城
* @since 2018年11月11日
*/
@Configuration
@EnableSwaggerMgUi(
selfDoc = false,// 不开启自身的文档,本项目只当管理文档的项目使用
defaultResources = {// selfDoc=false时有用启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
//"http://localhost:8080/swagger-resources"
}
)
public class SwaggerConfiguration {
}

View File

@@ -0,0 +1,52 @@
package com.zyplayer.doc.manage.framework.config;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
@Component
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
format.setLenient(true);
DateFormatter dateFormatter = new DateFormatter();
dateFormatter.setPattern("yyyy-MM-dd HH:mm:ss");
dateFormatter.setLenient(true);
registry.addFormatter(dateFormatter);
}
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter() {
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
List<MediaType> supportedMediaTypes = new ArrayList<>();
supportedMediaTypes.add(new MediaType("application", "json", Charset.forName("UTF-8")));
fastJsonHttpMessageConverter.setSupportedMediaTypes(supportedMediaTypes);
FastJsonConfig fastJsonConfig = new FastJsonConfig();
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteDateUseDateFormat);
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
return fastJsonHttpMessageConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, fastJsonHttpMessageConverter());
}
}

View File

@@ -0,0 +1,65 @@
package com.zyplayer.doc.manage.repository.manage.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
/**
* <p>
*
* </p>
*
* @author 暮光:城中城
* @since 2018-11-27
*/
public class ZyplayerStorage implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private String docKey;
private String docValue;
private Date creationTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDocKey() {
return docKey;
}
public void setDocKey(String docKey) {
this.docKey = docKey;
}
public String getDocValue() {
return docValue;
}
public void setDocValue(String docValue) {
this.docValue = docValue;
}
public Date getCreationTime() {
return creationTime;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
@Override
public String toString() {
return "ZyplayerStorage{" + "id=" + id + ", docKey=" + docKey + ", docValue=" + docValue + ", creationTime=" + creationTime + "}";
}
}

View File

@@ -0,0 +1,18 @@
package com.zyplayer.doc.manage.repository.manage.mapper;
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author 暮光:城中城
* @since 2018-11-27
*/
public interface ZyplayerStorageMapper extends BaseMapper<ZyplayerStorage> {
Integer selectTop();
}

View File

@@ -0,0 +1,94 @@
package com.zyplayer.doc.manage.repository.support.generator;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.FileOutConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
public class CodeGenerator {
public static void main(String[] args) {
final String moduleName = "manage";
final String[] tableName = { "zyplayer_storage" };
// 代码生成器
AutoGenerator mpg = new AutoGenerator();
// 全局配置
GlobalConfig gc = new GlobalConfig();
final String projectPath = System.getProperty("user.dir");
gc.setOutputDir(projectPath + "/src/main/java");
gc.setAuthor("暮光:城中城");
gc.setOpen(false);
gc.setDateType(DateType.ONLY_DATE);
gc.setServiceName("%sService");
mpg.setGlobalConfig(gc);
// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:mysql://127.0.0.1:3306/zyplayer-doc-manage?useUnicode=true&useSSL=false&characterEncoding=utf8");
// dsc.setSchemaName("public");
dsc.setDriverName("com.mysql.jdbc.Driver");
dsc.setUsername("root");
dsc.setPassword("11111");
mpg.setDataSource(dsc);
// 包配置
final PackageConfig pc = new PackageConfig();
pc.setModuleName(null);
pc.setParent("com.zyplayer.doc.manage");
pc.setController("web");
pc.setEntity("repository.manage.entity");
pc.setMapper("repository.manage.mapper");
pc.setService("service.manage");
pc.setServiceImpl("service.manage.impl");
mpg.setPackageInfo(pc);
// 自定义配置
InjectionConfig cfg = new InjectionConfig() {
@Override
public void initMap() {
// to do nothing
}
};
List<FileOutConfig> focList = new ArrayList<>();
focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {
@Override
public String outputFile(TableInfo tableInfo) {
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg);
mpg.setTemplate(new TemplateConfig().setXml(null));
// 策略配置
StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel);
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
// strategy.setSuperEntityClass("com.baomidou.ant.common.BaseEntity");
strategy.setEntityLombokModel(false);
strategy.setRestControllerStyle(true);
// strategy.setSuperControllerClass("com.baomidou.ant.common.BaseController");
// strategy.setSuperEntityColumns("id");
strategy.setInclude(tableName);// 表名
strategy.setControllerMappingHyphenStyle(true);
strategy.setTablePrefix(pc.getModuleName() + "_");
mpg.setStrategy(strategy);
mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute();
}
}

View File

@@ -0,0 +1,16 @@
package com.zyplayer.doc.manage.service.manage;
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 服务类
* </p>
*
* @author 暮光:城中城
* @since 2018-11-27
*/
public interface ZyplayerStorageService extends IService<ZyplayerStorage> {
}

View File

@@ -0,0 +1,20 @@
package com.zyplayer.doc.manage.service.manage.impl;
import com.zyplayer.doc.manage.repository.manage.entity.ZyplayerStorage;
import com.zyplayer.doc.manage.repository.manage.mapper.ZyplayerStorageMapper;
import com.zyplayer.doc.manage.service.manage.ZyplayerStorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author 暮光:城中城
* @since 2018-11-27
*/
@Service
public class ZyplayerStorageServiceImpl extends ServiceImpl<ZyplayerStorageMapper, ZyplayerStorage> implements ZyplayerStorageService {
}

View File

@@ -0,0 +1,30 @@
package com.zyplayer.doc.manage.web.swagger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zyplayer.doc.manage.repository.manage.mapper.ZyplayerStorageMapper;
/**
* <p>
* 前端控制器
* </p>
*
* @author 暮光:城中城
* @since 2018-11-27
*/
@RestController
@RequestMapping("/zyplayer-storage")
public class ZyplayerStorageController {
@Autowired
ZyplayerStorageMapper zyplayerStorageMapper;
@RequestMapping("/mapper")
public String mapper() {
Integer selectTop = zyplayerStorageMapper.selectTop();
return "selectTop:" + selectTop;
}
}