Ver a proveniência

初始

master
郑根木 há 2 anos
ascendente
cometimento
4611eb65db
5 ficheiros alterados com 235 adições e 2 eliminações
  1. +8
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java
  2. +3
    -2
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java
  3. +2
    -0
      smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java
  4. +111
    -0
      smtweb-framework/sw-framework-core/src/main/resources/config/demo.json
  5. +111
    -0
      smtweb-framework/sw-framework-core/target/classes/config/demo.json

+ 8
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/config/WebMvcConfig.java Ver ficheiro

@@ -16,8 +16,10 @@ import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -121,4 +123,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
log.error("'/files/**' 已经被注册");
}
}

// 所有返回接口Content-Type默认都返回application/json
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}
}

+ 3
- 2
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/mvc/controller/ApiController.java Ver ficheiro

@@ -1,6 +1,7 @@
package cc.smtweb.framework.core.mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PreDestroy;
@@ -25,7 +26,7 @@ public class ApiController {
* @return 返回对象,一般在函数里面使用R
* @throws Exception API处理异常
*/
@GetMapping("/api/**")
@GetMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public Object commonGet(@RequestParam Map<String, Object> params,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String apiUrl = request.getRequestURI().substring(5);
@@ -41,7 +42,7 @@ public class ApiController {
* @return 返回对象,一般在函数里面使用R
* @throws Exception API处理异常
*/
@PostMapping("/api/**")
@PostMapping(value = "/api/**", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public Object commonPost(@RequestParam Map<String, Object> params, @RequestBody(required = false) String body,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String apiUrl = request.getRequestURI().substring(5);


+ 2
- 0
smtweb-framework/sw-framework-core/src/main/java/cc/smtweb/framework/core/util/JsonUtil.java Ver ficheiro

@@ -7,6 +7,7 @@ import cc.smtweb.framework.core.db.vo.ModelTable;
import cc.smtweb.framework.core.exception.JsonParseException;
import cc.smtweb.framework.core.util.jackson.*;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
@@ -69,6 +70,7 @@ public class JsonUtil {
module.addDeserializer(java.util.Date.class, new DateDeserializer());

mapper.registerModule(module);
mapper.enable(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN);
}

public static JsonNode readTree(String body) {


+ 111
- 0
smtweb-framework/sw-framework-core/src/main/resources/config/demo.json Ver ficheiro

@@ -0,0 +1,111 @@
{
"fields": [
{
"name": "mc_id",
"fieldType": "1",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID"
},
{
"name": "mc_parent_id",
"fieldType": "4",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "2"
},
{
"name": "mc_prj_id",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "1"
},
{
"name": "mc_code",
"fieldType": "2",
"dataType": "CODE",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_name",
"fieldType": "3",
"dataType": "NAME",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_create_uid",
"fieldType": "7",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "创建人",
"link": "",
"editor": ""
},
{
"name": "mc_update_uid",
"fieldType": "9",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "最后更新人",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "8",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_update_at",
"fieldType": "10",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "最后更新时间",
"link": "",
"editor": ""
}
],
"indexes": [
{
"name": "pk",
"fields": "mc_id",
"type": "P"
}
],
"caches": [
{
"name": "pr",
"title": "按树型",
"fields": "mc_parent_id",
"type": "L"
},
{
"name": "prj",
"title": "按目录",
"fields": "mc_prj_id",
"type": "L"
}
]
}

+ 111
- 0
smtweb-framework/sw-framework-core/target/classes/config/demo.json Ver ficheiro

@@ -0,0 +1,111 @@
{
"fields": [
{
"name": "mc_id",
"fieldType": "1",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID"
},
{
"name": "mc_parent_id",
"fieldType": "4",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "2"
},
{
"name": "mc_prj_id",
"fieldType": "",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "ID",
"link": "1"
},
{
"name": "mc_code",
"fieldType": "2",
"dataType": "CODE",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_name",
"fieldType": "3",
"dataType": "NAME",
"null": "0",
"default": "",
"title": "编码",
"link": "",
"editor": ""
},
{
"name": "mc_create_uid",
"fieldType": "7",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "创建人",
"link": "",
"editor": ""
},
{
"name": "mc_update_uid",
"fieldType": "9",
"dataType": "ID",
"null": "1",
"default": "-1",
"title": "最后更新人",
"link": "",
"editor": ""
},
{
"name": "mc_create_at",
"fieldType": "8",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "创建时间",
"link": "",
"editor": ""
},
{
"name": "mc_update_at",
"fieldType": "10",
"dataType": "DATETIME",
"null": "1",
"default": "-1",
"title": "最后更新时间",
"link": "",
"editor": ""
}
],
"indexes": [
{
"name": "pk",
"fields": "mc_id",
"type": "P"
}
],
"caches": [
{
"name": "pr",
"title": "按树型",
"fields": "mc_parent_id",
"type": "L"
},
{
"name": "prj",
"title": "按目录",
"fields": "mc_prj_id",
"type": "L"
}
]
}

Carregando…
Cancelar
Guardar