13. AIアラームデータの保存
curl -X POST -H 'X-Access-Token:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6Inlka2p5dyIsImV4cCI6MTczOTAwNjEyMH0.lX1UmFhyJX3SzvJN0J8AQ-AOKpzH1RaIFVkOMj2ZS1Y' -F 'mineNo=340621002648' -F 'equipNo=renyuanweixian@10.100.5.79' -F 'eventTypeCode=A54A05' -F 'modelId=1852346184677601282' -F 'alarmContent=井底车场行车区域人员避让监测' -F 'occurTime=2025-07-09 23:46:24' http://localhost:8090/aiAlarm/save
12. 特定のフィールド内の文字列を置換
UPDATE users
SET email = REPLACE(email, '古いメールアドレス', '新しいメールアドレス')
WHERE email LIKE '%古いメールアドレス%';
11. サーバーの時刻同期
sudo vim /etc/systemd/timesyncd.conf
NTP=ntp.tencent.com
FallbackNTP=ntp1.tencent.com,ntp2.tencent.com,ntp3.tencent.com
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048
service systemd-timesyncd restart
chown -R ubuntu:ubuntu /home/aa
10. curlを使用したPOSTリクエスト(パラメータ付き)
curl -X POST -H 'X-Access-Token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjA3OTI2NDcsInVzZXJuYW1lIjoibGlyZW4ifQ.7-u5-GfA-K_EbDQcO6LsnJJumE2aCuonOxf-LYnVSNM' -F 'mineNo=370982030705' -F 'equipNo=ruqin@10.68.83.33' -F 'eventTypeCode=A03A06' -F 'modelId=1715203693151416321' -F 'alarmContent=人员进入:报警' -F 'occurTime=2024-07-12 10:32:07' http://localhost:8080/aiAlarm/saveDibholeEnter
9. サブクエリを使用した更新
UPDATE orders o
SET o.customer_id = ( SELECT c.id FROM customers c WHERE c.name = '顧客A' )
WHERE
o.id = ( SELECT p.order_id FROM payments p WHERE p.amount > 1000 )
update inventory i set i.stock_level = (select quantity from stock_updates s where i.product_id = s.product_id)
8. npmインストールエラーの解決
pm ERR! invalid json response body at http://registry.npm.taobao.org/posthtml reason: Unexpected token < in JSON at position 0
1. まず以下のコマンドを実行します
npm config set proxy null
npm config set https-proxy null
2. 次に実行します: npm config set registry http://registry.npmmirror.com/
3. 最後に実行します: npm install -g cnpm --registry=https://registry.npmmirror.com/
通常、これで解決します。
7. MyBatisのResultMap
<resultMap id="productMap" type="com.example.entity.Product">
<id property="id" column="id"/>
<result property="productName" column="product_name"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<association property="productDetail" javaType="com.example.entity.ProductDetail">
<id property="id" column="detail_id"/>
<result property="detailInfo" column="detail_info"/>
<result property="createBy" column="detail_create_by"/>
<result property="createTime" column="detail_create_time"/>
</association>
</resultMap>
<select id="listByPage" parameterType="com.example.entity.Product" resultMap="productMap">
SELECT p.*, d.*
FROM products p
LEFT JOIN product_details d ON p.id = d.product_id
WHERE p.status = '0' AND p.code like concat(#{entity.code},'%')
<if test="entity.year!= null">
<choose>
<when test="entity.month!= null">
AND ( ( DATE_FORMAT(p.start_time,'%Y-%c')
AND DATE_FORMAT(p.end_time,'%Y-%c') concat(concat(#{entity.year}, '-'), #{entity.month}) ) ]]>
or ( DATE_FORMAT(p.start_time,'%Y-%c') = concat(concat(#{entity.year}, '-'), #{entity.month})
or DATE_FORMAT(p.end_time,'%Y-%c') = concat(concat(#{entity.year}, '-'), #{entity.month}) ) )
</when>
<otherwise>
AND (p.start_time REGEXP #{entity.year} or p.end_time REGEXP #{entity.year})
</otherwise>
</choose>
</if>
</select>
6. MyBatisの一对多関連
<?xml version="1.0" encoding="UTF-8"?>
<mapper namespace="com.example.mapper.OrderMapper">
<resultMap id="orderResultMap" type="com.example.entity.Order">
<id property="id" column="id"/>
<result property="orderNumber" column="order_number"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<collection property="orderItems" ofType="com.example.entity.OrderItem"
select="selectOrderItems" column="{orderId = id}"/>
</resultMap>
<select id="listByPage" parameterType="com.example.entity.Order" resultMap="orderResultMap">
SELECT o.* FROM orders o
WHERE o.status = '0'
</select>
<select id="selectOrderItems" resultType="com.example.entity.OrderItem">
SELECT oi.* FROM order_items oi
<where>
oi.order_id = #{orderId}
</where>
</select>
</mapper>
public interface OrderMapper extends BaseMapper<Order> {
List<Order> listByPage(Page<Order> page, @Param("entity") Order order);
List<Object> selectOrderItems();
}
5. Spring Bootサービスの起動スクリプト
APP=app.jar
# アプリケーションを停止
kill -9 $(ps -ef | grep $APP | grep -v grep | awk '{ print $2 }')
# アプリケーションを起動
nohup java -jar -Djasypt.encryptor.password=mySecretKey app.jar > app.log 2>&1 &
4. データベースの一部データをエクスポート
mysqldump -uroot -ppassword -hlocalhost -P3306 --databases ecommerce --tables products --where="category_id='123' " >/backup/products_123.sql
3. RestTemplateを使用したGETリクエスト(複雑なパラメータとヘッダー)
private final static RestTemplate RT;
static {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(3000);
requestFactory.setReadTimeout(3000);
RT = new RestTemplate(requestFactory);
// 文字化けの解決
RT.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
}
public void fetchDeviceData() throws EncoderException, UnsupportedEncodingException {
String apiKey = getApiKey();
String url = "http://api.example.com/devices/?filter={json}";
String json = "{ "status": "active", "type": [{ "id": 456, "name": "sensor", "active": true }, { "id": 789, "name": "actuator", "active": false } ], "location": "warehouse", "page": 1, "limit": 50 }";
Map<String,String> map = new HashMap<>();
map.put("json",json);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType(MediaType.APPLICATION_JSON_VALUE));
headers.set("X-API-Key", apiKey);
HttpEntity<String> httpEntity = new HttpEntity<>(null, headers);
ResponseEntity<String> responseEntity = RT.exchange(url, HttpMethod.GET, httpEntity, String.class,map);
if (responseEntity != null && responseEntity.getBody() != null) {
System.out.println("応答結果:" + responseEntity.getBody());
} else {
System.out.println("クエリに失敗しました");
}
}
2. ローカルリポジトリへのJARファイルのインストール
mvn install:install-file -Dfile=utils-2.0.jar -Dpackaging=jar
1. 依存関係ツリーの分析
mvn dependency:tree -Dverbose -Dincludes=org.apache.httpcomponents:httpclient > dependency_tree.txt