北京经济技术开发区经开区虚拟城市项目-【后端】-服务,Poi,企业,地块等定制接口
13693261870
2023-10-07 b7f0283f5b7506013e890a55f3adf849457f7e9d
支持跨域访问
已添加1个文件
已修改3个文件
131 ■■■■■ 文件已修改
src/main/java/com/smartearth/poiexcel/config/WebConfig.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/controller/EntController.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/mapper/QiYeMapper.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/QiYeMapper.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/config/WebConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,92 @@
package com.smartearth.poiexcel.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.*;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
 * Web配置类
 * @author WWW
 */
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // è®¾ç½®è®¿é—®è·¯å¾„为 â€œ/” è·³è½¬åˆ°æŒ‡å®šé¡µé¢
        registry.addViewController("/").setViewName("redirect:/swagger-ui.html");
        // è®¾ç½®ä¸ºæœ€é«˜ä¼˜å…ˆçº§
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }
    /**
     * swagger控制
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
    /**
     * å¿½ç•¥url地址大小写
     */
    @Override
    protected void configurePathMatch(PathMatchConfigurer configurer) {
        AntPathMatcher matcher = new AntPathMatcher();
        matcher.setCaseSensitive(false);
        configurer.setPathMatcher(matcher);
    }
    /**
     * è·¨åŸŸè¯·æ±‚
     */
    @Override
    protected void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowCredentials(true)
                .allowedOrigins("*")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")
                .maxAge(3600);
    }
    /**
     * æ·»åŠ ç»Ÿä¸€çš„æ‹¦æˆªå™¨
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
    }
    /**
     * å¤„理json格式,值null的转换为""
     */
    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
        FastJsonConfig config = new FastJsonConfig();
        config.setSerializerFeatures(
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteMapNullValue,
                //SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullBooleanAsFalse);
        // ç»“果是否格式化,默认为false
        //SerializerFeature.PrettyFormat);
        converter.setFastJsonConfig(config);
        converter.setDefaultCharset(StandardCharsets.UTF_8);
        converters.add(converter);
    }
}
src/main/java/com/smartearth/poiexcel/controller/EntController.java
@@ -47,6 +47,21 @@
    @Value("${address.code.url}")
    private String addressCodeUrl;
    @ApiOperation(value = "根据名称模糊查询企业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "企业名称或地址", dataType = "String", paramType = "query", example = "")
    })
    @GetMapping({"/selectByName"})
    public ResponseMsg<Object> selectByName(String name) {
        try {
            List<EntEntity> list = qiYeMapper.selectByName(StringHelper.getLikeStr(name));
            return success(null == list ? 0 : list.size(), list);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
    @ApiOperation(value = "查询令牌")
    @GetMapping({"/selectToken"})
    public ResponseMsg<Object> selectToken() {
@@ -59,7 +74,7 @@
        }
    }
    @ApiOperation(value = "查询企业")
    @ApiOperation(value = "查询企业信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "String", paramType = "query", example = "2023-06-29"),
@@ -130,7 +145,7 @@
        }
    }
    @ApiOperation(value = "分页查询")
    @ApiOperation(value = "分页查询企业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1")
src/main/java/com/smartearth/poiexcel/mapper/QiYeMapper.java
@@ -15,6 +15,14 @@
@Repository
public interface QiYeMapper {
    /**
     * æ ¹æ®åç§°æ¨¡ç³ŠæŸ¥è¯¢
     *
     * @param name
     * @return
     */
    public List<EntEntity> selectByName(@Param("name") String name);
    /**
     * æŸ¥è¯¢è¡Œæ•°
     *
     * @return
src/main/resources/mapper/QiYeMapper.xml
@@ -1,6 +1,18 @@
<?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="com.smartearth.poiexcel.mapper.QiYeMapper">
    <select id="selectByName" resultType="com.smartearth.poiexcel.entity.EntEntity">
        select *
        from smart_earth.yz_qiyexinxi
        <where>
            <if test="name != null">
                upper(entName) like #{name} or upper(address) like #{name}
            </if>
        </where>
        order by entName
        limit 10;
    </select>
    <select id="selectCount" resultType="java.lang.Integer">
        select count(*)
        from smart_earth.yz_qiyexinxi