Jackson 对象与json数据互转工具类JacksonUtil

news/2024/11/27 23:22:49/

下面是一个基于 Jackson工具类 JacksonUtil,用于在 Java 项目中实现对象与 JSON 数据之间的互相转换。该工具类具有简洁、易用、通用的特点。

package com.fy.common.util;import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.databind.type.MapType;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import com.fy.common.constant.ObjectConstant;
import com.fy.common.constant.StringConstant;
import com.fy.common.custom.CustomDateDeserializer;
import com.fy.common.custom.CustomDateSerializer;
import lombok.NonNull;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;import java.io.*;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public enum JacksonUtil {/*** 单例*/i;/*** convert json to javabean or javabean to json.*/private ObjectMapper mapper;private TypeReference<Map<String, Object>> mapType = new TypeReference<Map<String, Object>>() {} ;private TypeReference<List<Map<String, Object>>> listmType = new TypeReference<List<Map<String, Object>>>() {};static {i.mapper = new ObjectMapper();i.mapper.setTimeZone(ObjectConstant.DatexFormatter.TIME_ZONE_E8);// 对于空的对象转json的时候不抛出错误i.mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);// 禁用遇到未知属性抛出异常i.mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);// 序列化BigDecimal时不使用科学计数法输出i.mapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);i.mapper.registerModule(sqltimeModule());i.mapper.registerModule(localtimeModule());}private  static SimpleModule sqltimeModule() {SimpleModule sqltimeModule = new SimpleModule();sqltimeModule.addSerializer(Timestamp.class, new CustomDateSerializer.TimestampSerializer());sqltimeModule.addSerializer(Date.class, new CustomDateSerializer.SqlDateSerializer());sqltimeModule.addSerializer(Time.class, new CustomDateSerializer.SqlTimeSerializer());sqltimeModule.addDeserializer(Timestamp.class, new CustomDateDeserializer.TimestampDeserializer());sqltimeModule.addDeserializer(Date.class, new CustomDateDeserializer.SqlDateDeserializer());sqltimeModule.addDeserializer(Time.class, new CustomDateDeserializer.SqlTimeDeserializer());return sqltimeModule;}private static JavaTimeModule localtimeModule() {JavaTimeModule localtimeModule = new JavaTimeModule();LocalDateTimeSerializer datimeSlizer = new LocalDateTimeSerializer(ObjectConstant.DatexFormatter.STANDARD_DATETIME);LocalDateSerializer dateSlizer = new LocalDateSerializer(ObjectConstant.DatexFormatter.STANDARD_DATE);LocalTimeSerializer timeSlizer = new LocalTimeSerializer(ObjectConstant.DatexFormatter.STANDARD_TIME);LocalDateTimeDeserializer datimeDlizer = new LocalDateTimeDeserializer(ObjectConstant.DatexFormatter.STANDARD_DATETIME);LocalDateDeserializer dateDlizer = new LocalDateDeserializer(ObjectConstant.DatexFormatter.STANDARD_DATE);LocalTimeDeserializer timeDlizer = new LocalTimeDeserializer(ObjectConstant.DatexFormatter.STANDARD_TIME);localtimeModule.addSerializer(LocalDateTime.class, datimeSlizer);localtimeModule.addSerializer(LocalDate.class, dateSlizer);localtimeModule.addSerializer(LocalTime.class, timeSlizer);localtimeModule.addDeserializer(LocalDateTime.class, datimeDlizer);localtimeModule.addDeserializer(LocalDate.class, dateDlizer);localtimeModule.addDeserializer(LocalTime.class, timeDlizer);return localtimeModule;}/*** 	创建一个JSON对象*/public static ObjectNode createObjectNode() {return i.mapper.createObjectNode();}/*** 	创建一个JSON数组*/public static ArrayNode createArrayNode() {return i.mapper.createArrayNode();}/***	 判断一个字符串是否是合法的json格式字符串**/public static boolean isJson(String jsonStr) {try {i.mapper.readTree(jsonStr);return true;} catch (JsonProcessingException e) {return false;}}/*** 	字符串转Json对象**/public static ObjectNode readJsonObject(String jsonStr) {JsonNode node = null;ObjectNode objNode = null;try {node = i.mapper.readTree(jsonStr);if (!node.isArray()) {objNode = (ObjectNode) node;}} catch (IOException e) {throw new RuntimeException(e);}return objNode;}/*** 	字符串转Json数组*/public static ArrayNode readJsonArray(String jsonStr) {JsonNode node = null;ArrayNode arrNode = null;try {node = i.mapper.readTree(jsonStr);if (node.isArray()) {arrNode = (ArrayNode) node;}} catch (IOException e) {throw new RuntimeException(e);}return arrNode;}/*** 	字符串转JsonNode*/public static JsonNode readJson(String jsonStr) {try {return i.mapper.readTree(jsonStr);} catch (IOException e) {throw new RuntimeException(e);}}/*** 	字节数组转JSON*/public static JsonNode readJson(byte[] content) {try {return i.mapper.readTree(content);} catch (IOException e) {throw new RuntimeException(e);}}/*** 将JSON对象转成Map** @param objectNode   json非数组对象* @return Map*/public static Map<String, Object> jsonObjct2Map(ObjectNode objectNode) {return i.mapper.convertValue(objectNode, i.mapType);}/*** 	将JSON对象转成类型** @param objectNode json非数组对象* @return Map*/public static <T> T jsonObjct2Object(ObjectNode objectNode, Class<T> toType) {return i.mapper.convertValue(objectNode, toType);}/*** 	将JSON对象转成List<Map>集合** @param arryNode  json数组对象* @return List*/public static List<Map<String, Object>> jsonArray2List(ArrayNode arryNode) {return i.mapper.convertValue(arryNode, i.listmType);}/*** 	将JsonNode转成指定类型的** @param jsonNode* @return T*/public static <T> T jsonNode2Type(JsonNode jsonNode, TypeReference<T> typeReference) {return i.mapper.convertValue(jsonNode, typeReference);}/*** 	将字符串转成指定class类型对象*/public static <T> T readJson(String jsonStr, Class<T> T) {T obj = null;try {obj = i.mapper.readValue(jsonStr, T);} catch (JsonProcessingException e) {throw new RuntimeException(e);}return obj;}/*** 	将字符串转成指定类型的对象*/public static <T> T readJson(String jsonStr, TypeReference<T> typeReference) {T obj = null;try {obj = i.mapper.readValue(jsonStr, typeReference);} catch (JsonProcessingException e) {throw new RuntimeException(e);}return obj;}/*** URL请求返回结果体转换对象* 案例: URL url = new URL("<a href="https://jsonplaceholder.typicode.com/posts/1">...</a>"); //远程服务URL*       PostDTO post = JacksonUtil.readJson(url, PostDTO.class);*/public static <T> T readJson(@NonNull URL url, Class<T> type) {try {return i.mapper.readValue(url, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** URL请求返回结果体转换对象*/public static <T> T readJson(@NonNull URL url, TypeReference<T> type) {try {return i.mapper.readValue(url, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** URL请求返回结果体转换list集合*/public static <T> List<T> readJsonList(@NonNull URL url, Class<T> type) {try {CollectionType collectionType = i.mapper.getTypeFactory().constructCollectionType(ArrayList.class, type);return i.mapper.readValue(url, collectionType);} catch (IOException e) {throw new RuntimeException(e);}}/*** 输入流转换为对象*/public static <T> T readJson(@NonNull InputStream inputStream, Class<T> type) {try {return i.mapper.readValue(inputStream, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** 输入流转换为对象*/public static <T> T readJson(@NonNull InputStream inputStream, TypeReference<T> type) {try {return i.mapper.readValue(inputStream, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** 读取文件中JSON格式文本转换对象*/public static <T> T readJson(@NonNull File file, Class<T> type) {try {return i.mapper.readValue(file, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** 读取文件中JSON格式文本转换对象*/public static <T> T readJson(@NonNull File file, TypeReference<T> type) {try {return i.mapper.readValue(file, type);} catch (IOException e) {throw new RuntimeException(e);}}/*** 读取文件中JSON格式文本转换(List)对象*/public static <T> List<T> readJsonList(@NonNull File file, Class<T> type) {try {CollectionType collectionType = i.mapper.getTypeFactory().constructCollectionType(ArrayList.class, type);return i.mapper.readValue(file, collectionType);} catch (IOException e) {throw new RuntimeException(e);}}/*** json字符串转换List集合* @param jsonString JSON字符串* @param cls        转换对象* @return list集合* @param <T> 目标对象类型*/public static <T> List<T> readJsonList(@NonNull String jsonString, Class<T> cls) {try {return i.mapper.readValue(jsonString, getCollectionType(cls));} catch (IOException e) {throw new RuntimeException(e);}}/*** Object对象转List集合*/public static <T> List<T> readJsonList(@NonNull Object obj, Class<T> cls) {try {String s = i.mapper.writeValueAsString(obj);return readJsonList(s, cls);} catch (JsonProcessingException e) {throw new RuntimeException(e);}}/*** JSON字符串转换Map集合*/public static Map<String, Object> readJsonMap(@NonNull String json) {if (StringUtils.isEmpty(json)) {return null;}try {MapType mapType = i.mapper.getTypeFactory().constructMapType(HashMap.class, String.class, Object.class);return i.mapper.readValue(json, mapType);} catch (IOException e) {throw new RuntimeException(e);}}/*** 	将java对象转成字符串*/public static String writeJson(Object entity) {String str = StringConstant.Json.EMPTY_OBJECT;if (entity == null) {return str;}try {str = i.mapper.writeValueAsString(entity);} catch (JsonProcessingException e) {throw new RuntimeException(e);}return str;}/*** list集合转换为JSON字符串* @param list list集合* @return JSON字符串* @param <T> 目标对象类型*/public static <T> String writeString(@NonNull List<T> list) {try {return i.mapper.writeValueAsString(list);} catch (JsonProcessingException e) {throw new RuntimeException(e);}}/*** 序列化为JSON*/public static <T> void writeFile(@NonNull String path, List<T> list) {try (Writer writer = new FileWriter(path, true)) {i.mapper.writer().writeValues(writer).writeAll(list);} catch (Exception e) {throw new RuntimeException(e);}}/*** 序列化为JSON*/public static <T> void writeFile(@NonNull String path, T t) {try (Writer writer = new FileWriter(path, true)) {i.mapper.writer().writeValues(writer).write(t);} catch (Exception e) {throw new RuntimeException(e);}}/***	 将对象实体转换成Jackson的ObjectNode*/public static ObjectNode bean2ObjNode(Object bean) {return i.mapper.convertValue(bean, ObjectNode.class);}/*** 将对象转换成JsonNode*/public static JsonNode convertToJsonNode (Object object) {return i.mapper.valueToTree(object);}/*** 将Map转换成JsonNode*/public static JsonNode convertToJsonNode(Map<String,Object> map) {return i.mapper.convertValue(map, JsonNode.class);}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return String,默认为 null*/public static String getAsString(String json, String key) {if (StringUtils.isEmpty(json)) {return null;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return null;}return getAsString(jsonNode);} catch (Exception e) {throw new RuntimeException(e);}}private static String getAsString(JsonNode jsonNode) {return jsonNode.isTextual() ? jsonNode.textValue() : jsonNode.toString();}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return int,默认为 0*/public static int getAsInt(String json, String key) {if (StringUtils.isEmpty(json)) {return 0;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return 0;}return jsonNode.isInt() ? jsonNode.intValue() : Integer.parseInt(getAsString(jsonNode));} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return long,默认为 0*/public static long getAsLong(String json, String key) {if (StringUtils.isEmpty(json)) {return 0L;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return 0L;}return jsonNode.isLong() ? jsonNode.longValue() : Long.parseLong(getAsString(jsonNode));} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return double,默认为 0.0*/public static double getAsDouble(String json, String key) {if (StringUtils.isEmpty(json)) {return 0.0;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return 0.0;}return jsonNode.isDouble() ? jsonNode.doubleValue() : Double.parseDouble(getAsString(jsonNode));} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return BigInteger,默认为 0.0*/public static BigInteger getAsBigInteger(String json, String key) {if (StringUtils.isEmpty(json)) {return new BigInteger(String.valueOf(0.00));}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return new BigInteger(String.valueOf(0.00));}return jsonNode.isBigInteger() ? jsonNode.bigIntegerValue() : new BigInteger(getAsString(jsonNode));} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return BigDecimal,默认为 0.00*/public static BigDecimal getAsBigDecimal(String json, String key) {if (StringUtils.isEmpty(json)) {return new BigDecimal("0.00");}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return new BigDecimal("0.00");}return jsonNode.isBigDecimal() ? jsonNode.decimalValue() : new BigDecimal(getAsString(jsonNode));} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return boolean, 默认为false*/public static boolean getAsBoolean(String json, String key) {if (StringUtils.isEmpty(json)) {return false;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return false;}if (jsonNode.isBoolean()) {return jsonNode.booleanValue();} else {if (jsonNode.isTextual()) {String textValue = jsonNode.textValue();if (StringConstant.Number.ONE.equals(textValue)) {return true;} else {return BooleanUtils.toBoolean(textValue);}} else {//numberreturn BooleanUtils.toBoolean(jsonNode.intValue());}}} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return byte[], 默认为 null*/public static byte[] getAsBytes(String json, String key) {if (StringUtils.isEmpty(json)) {return null;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return null;}return jsonNode.isBinary() ? jsonNode.binaryValue() : getAsString(jsonNode).getBytes();} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return object, 默认为 null*/public static <T> T getAsObject(String json, String key, Class<T> type) {if (StringUtils.isEmpty(json)) {return null;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return null;}JavaType javaType = i.mapper.getTypeFactory().constructType(type);return from(getAsString(jsonNode), javaType);} catch (Exception e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段** @param json JSON字符串* @param key  对象属性名* @return list, 默认为 null*/public static <T> List<T> getAsList(String json, String key, Class<T> type) {if (StringUtils.isEmpty(json)) {return null;}try {JsonNode jsonNode = getAsJsonObject(json, key);if (null == jsonNode) {return null;}CollectionType collectionType = i.mapper.getTypeFactory().constructCollectionType(ArrayList.class, type);return from(getAsString(jsonNode), collectionType);} catch (Exception e) {throw new RuntimeException(e);}}/*** JSON反序列化*/private static <T> T from(String json, Type type) {if (StringUtils.isEmpty(json)) {return null;}try {JavaType javaType = i.mapper.getTypeFactory().constructType(type);return i.mapper.readValue(json, javaType);} catch (IOException e) {throw new RuntimeException(e);}}/*** 从json串中获取某个字段* @return JsonNode, 默认为 null*/public static JsonNode getAsJsonObject(String json, String key) {try {JsonNode node = i.mapper.readTree(json);if (null == node) {return null;}return node.get(key);} catch (IOException e) {throw new RuntimeException(e);}}/*** 向json中添加属性* @return json*/public static <T> String add(String json, String key, T value) {try {JsonNode node = i.mapper.readTree(json);add(node, key, value);return node.toString();} catch (IOException e) {throw new RuntimeException(e);}}/*** 向json中添加属性*/private static <T> void add(JsonNode jsonNode, String key, T value) {if (value instanceof String) {((ObjectNode) jsonNode).put(key, (String) value);} else if (value instanceof Short) {((ObjectNode) jsonNode).put(key, (Short) value);} else if (value instanceof Integer) {((ObjectNode) jsonNode).put(key, (Integer) value);} else if (value instanceof Long) {((ObjectNode) jsonNode).put(key, (Long) value);} else if (value instanceof Float) {((ObjectNode) jsonNode).put(key, (Float) value);} else if (value instanceof Double) {((ObjectNode) jsonNode).put(key, (Double) value);} else if (value instanceof BigDecimal) {((ObjectNode) jsonNode).put(key, (BigDecimal) value);} else if (value instanceof BigInteger) {((ObjectNode) jsonNode).put(key, (BigInteger) value);} else if (value instanceof Boolean) {((ObjectNode) jsonNode).put(key, (Boolean) value);} else if (value instanceof byte[]) {((ObjectNode) jsonNode).put(key, (byte[]) value);} else {((ObjectNode) jsonNode).put(key, writeJson(value));}}/*** 除去json中的某个属性* @return json*/public static String remove(String json, String key) {try {JsonNode node = i.mapper.readTree(json);((ObjectNode) node).remove(key);return node.toString();} catch (IOException e) {throw new RuntimeException(e);}}/*** 修改json中的属性*/public static <T> String update(String json, String key, T value) {try {JsonNode node = i.mapper.readTree(json);((ObjectNode) node).remove(key);add(node, key, value);return node.toString();} catch (IOException e) {throw new RuntimeException(e);}}/*** 格式化Json(美化)* @return json*/public static String format(String json) {try {JsonNode node = i.mapper.readTree(json);return i.mapper.writerWithDefaultPrettyPrinter().writeValueAsString(node);} catch (IOException e) {throw new RuntimeException(e);}}/*** 获取泛型的Collection Type** @param elementClasses 实体bean* @return JavaType Java类型*/private static JavaType getCollectionType(Class<?>... elementClasses) {return i.mapper.getTypeFactory().constructParametricType(List.class, elementClasses);}}
package com.fy.common.custom;import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import lombok.SneakyThrows;import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.GregorianCalendar;/*** 全局日期(针对 java.sql.Date、java.sql.Time、java.sql.TimeStamp三种)* jackson反解析*/
public class CustomDateDeserializer {public static class TimestampDeserializer extends JsonDeserializer<Timestamp> {@Overridepublic Timestamp deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {return Timestamp.valueOf(p.getValueAsString());}}public static class SqlDateDeserializer extends JsonDeserializer<Date> {@Overridepublic Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {return Date.valueOf(p.getValueAsString());}}public static class SqlTimeDeserializer extends JsonDeserializer<Time> {@Overridepublic Time deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {return Time.valueOf(p.getValueAsString());}}public static class SqlXMLGregorianCalendarDeserializer extends JsonDeserializer<XMLGregorianCalendar> {@SneakyThrows@Overridepublic XMLGregorianCalendar deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {Date date = Date.valueOf(p.getValueAsString());GregorianCalendar cal = new GregorianCalendar();cal.setTime(date);return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);}}}
package com.fy.common.custom;import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;import javax.xml.datatype.XMLGregorianCalendar;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;/*** 全局日期(针对 java.sql.Date、java.sql.Time、java.sql.TimeStamp三种)* jackson解析*/
public class CustomDateSerializer {public static class SqlDateSerializer extends JsonSerializer<Date> {@Overridepublic void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) throws IOException {gen.writeString(value.toString());}}public static class TimestampSerializer extends JsonSerializer<Timestamp> {@Overridepublic void serialize(Timestamp value, JsonGenerator gen, SerializerProvider serializers) throws IOException {gen.writeString(value.toString().substring(0, 19));}}public static class SqlTimeSerializer extends JsonSerializer<Time> {@Overridepublic void serialize(Time value, JsonGenerator gen, SerializerProvider serializers) throws IOException {gen.writeString(value.toString());}}public static class SqlXMLGregorianCalendarSerializer extends JsonSerializer<XMLGregorianCalendar> {@Overridepublic void serialize(XMLGregorianCalendar value, JsonGenerator gen, SerializerProvider serializers) throws IOException {gen.writeNumber(value.toGregorianCalendar().getTimeInMillis());}}}

其中StringConstant.JSON在这篇博客中有分享。
https://blog.csdn.net/qq_41520636/article/details/144006665?spm=1001.2014.3001.5501


http://www.ppmy.cn/news/1550463.html

相关文章

SQL99版外连接

外连接 看这样的场景&#xff0c;在ta和tb两表中查询没有对应年龄数据的学生姓名和年龄 SELECT tb.name,ta.age FROM tb INNER JOIN ta ON tb.ta_idta.id WHERE ta.id IS NULL; 结果没有,所以前面的查询是解决不了这种问题&#xff01;&#xff01;&#xff01; 所以外连接…

Spring Boot 核心逻辑与工作原理详解

当然可以&#xff01;下面是一篇关于 Spring Boot 逻辑的文章&#xff0c;涵盖了其核心概念、主要特点和工作原理。 Spring Boot 的逻辑与工作原理 1. 引言 Spring Boot 是一个基于 Java 的框架&#xff0c;旨在简化新 Spring 应用的初始搭建和开发过程。它通过提供默认配置和…

第六章 Spring Boot快速⼊⻔ —— Spring Boot工作机制

前言: Spring Boot的工作机制主要围绕其自动配置、起步依赖、嵌入式Web服务器以及配置管理等方面展开。 自动配置:是通过预定义的约定和条件,它极大地简化了应用的开发过程,这一机制使得开发人员可以更加专注于业务逻辑的实现,而无需花费大量时间在繁琐的配置上。起步依赖…

如何在 Ubuntu 22.04 上安装带有 Nginx 的 ELK Stack

今天我们来聊聊如何在 Ubuntu 22.04 服务器上安装 ELK Stack&#xff0c;并集成 Nginx 作为 Web 服务器&#xff0c;同时使用 Let’s Encrypt Certbot 进行 SSL 认证。ELK Stack&#xff0c;包括 Elasticsearch、Logstash 和 Kibana&#xff0c;是一套强大的工具&#xff0c;用…

数组中元素互不相同的判断(暴力以及Trie 优化)

题目&#xff1a; 代码&#xff08;暴力&#xff09; o(n^4) // 循环暴力 #include<bits/stdc.h> using namespace std;const int N 2e350; int a[N][N];int main() {int n, m;cin >> m >> n;for(int i 1; i < m; i ) {for(int j 1; j < n; j ) {…

【大语言模型】ACL2024论文-20 SCIMON:面向新颖性的科学启示机器优化

【大语言模型】ACL2024论文-20 SCIMON&#xff1a;面向新颖性的科学启示机器优化 目录 文章目录 【大语言模型】ACL2024论文-20 SCIMON&#xff1a;面向新颖性的科学启示机器优化目录摘要研究背景问题与挑战如何解决创新点算法模型实验效果推荐阅读指数&#xff1a;★★★★☆ …

(已解决)wps无法加载此加载项程序mathpage.wll

今天&#xff0c;在安装Mathtype的时候遇到了点问题&#xff0c;如图所示 尝试了网上的方法&#xff0c;将C:\Users\Liai_\AppData\Roaming\Microsoft\Word\STARTUP路径中的替换为32位的Mathtype加载项。但此时&#xff0c;word又出现了问题 后来知道了&#xff0c;这是因为64位…

2024“龙信杯“电子数据取证竞赛-服务器取证题目Writeup

服务器检材-分析 前置 提示&#xff1a;该服务器做了登录密码校验配置&#xff0c;如果没有拿到服务器的密码而直接仿真服务器&#xff0c;输入密码进入系统后&#xff0c;服务器会将部分数据给自动删除 前提&#xff1a;无 因为我们仿真进入服务器会自动删除文件&#xff0…