SpringBoot Request And Response

1, 简单参数
	定义方法形参,请求参数名与形参变量名一致。
	如果不一致,通过@RequestParam手动映射。
2,实体参数
	请求参数名,与实体对象的属性名一致,会自动接收封装。
3,数组集合参数
	数组:请求参数名与数组名一致,直接封装。
	集合:请求参数名与集合名一致,@RequestParam绑定关系。
4,日期参数
	@DateTimeFormat
5,JSON参数
	@RequestBody
6,路径参数
	@PathVariable
	@Autowired
	private HttpServletRequest request;

refer to:
https://www.bilibili.com/video/BV1kg4y1x7o6?p=70

Return Primary Key After Inserting In MyBatis

@Mapper
public interface EmpMapper {
 
	@Delete("delete from emp where id = #{id}")
	public void delete(Integer id);
 
	@Options(useGeneratedKeys = true, keyProperty = "id")
	@Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
			" values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
	public void insert(Emp emp);
 
	@Results({
		@Result(column = "dept_id", property = "deptId"),
		@Result(column = "create_time", property = "createTime"),
		@Result(column = "update_time", property = "updateTime")
	})
	@Select("select * from emp where id = #{id}")
	public Emp getById(Integer id);
 
	// or in application.properties
	// mybatis.configuration.map-underscore-to-camel-case=true
 
	//@Select("select * from emp where name like '%${name}%' and gender = #{gender} and " +
	//		"entrydate between #{begin} and #{end} order by update_time desc ")
	@Select("select * from emp where name like concat('%', #{name}, '%') and gender = #{gender} and " +
			"entrydate between #{begin} and #{end} order by update_time desc ")
	public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);
}

refer to:
https://www.bilibili.com/video/BV1kg4y1x7o6/?p=124

Remove Returns of Text

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#define ENDS_WITH(ch0, ch1) ((unsigned char)line[len - 3] == (ch1) && (unsigned char)line[len - 4] == (ch0))
 
/*
 * for gbk only.
 */
int main()
{
	FILE* fp = fopen("/mnt/hgfs/share/aaa1.txt", "r");
	FILE* fpOut = fopen("/mnt/hgfs/share/aaa2.txt", "w+");
	if (NULL == fp)
		return -1;
 
	char line[1024 * 10] = {0};
	while (NULL != fgets(line, sizeof(line) - 1, fp))
	{
		int len = strlen(line);
		if (0) // (len > 10)
		{
			printf("[%s]\n-1:%x\n-2:%x\n-3:%x\n-4:%x\n-5:%x\n-6:%x\n", 
					line,
					(unsigned int)(unsigned char)line[len - 1],
					(unsigned int)(unsigned char)line[len - 2],
					(unsigned int)(unsigned char)line[len - 3],
					(unsigned int)(unsigned char)line[len - 4],
					(unsigned int)(unsigned char)line[len - 5],
					(unsigned int)(unsigned char)line[len - 6]);
		}
		if (len >= 4)
		{
			do {
				if ((unsigned char)line[len - 1] != 0xa
						|| (unsigned char)line[len - 2] != 0xd)
					break;
				if (ENDS_WITH(0x80, 0x82))
				{
					// period
					break;
				}
 
				if (ENDS_WITH(0x80, 0x9d))
				{
					// double quotation mark
					break;
				}
				line[len - 2] = 0;
			} while (0);
		}
		fputs(line, fpOut);
	}
 
	fclose(fpOut);
	fclose(fp);
	return 1;
}

Unreasonable Input in std sort Lambda Expression

	struct Aa
	{
		int i0;
	};
	std::vector<Aa*> list_;
...
	std::sort(list_.begin(), list_.end(), [this, &end_dates](Aa* l, Aa* r) {
		return l->degree_ - r->degree_;
	});

Before the sort, I promise the members of list_ are all not null, but in the sort lambda expression, when running, we will be caught by a null pointer access SIGSEGV, for example, l is null.

Well, the good shot is,

...
	std::sort(list_.begin(), list_.end(), [this, &end_dates](Aa* l, Aa* r) {
		return l->degree_ > r->degree_;
	});

Scramble Web Site Images using TamperMonkey Script

// ==UserScript==
// @name         Euhat Web Site Images Download
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       euhat
// @match        https://www.sample.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=toutiao.com
// @grant           GM_xmlhttpRequest
// @grant           GM_setValue
// @grant           GM_getValue
// @grant           GM_addStyle
// @grant           GM_setClipboard
// @grant           GM_download
// @require         https://unpkg.com/vue@2
// ==/UserScript==
 
(function() {
	'use strict';
 
	var euForm = document.createElement("div");
	euForm.innerHTML = `
		<div id="euForm">
			<b>Here:</b>
			<button @click="euDownAll">Download All Image</button>
		</div>
	`;
 
 
 
	document.querySelector("html").appendChild(euForm);
 
	GM_addStyle(`
#euForm{
font-size : 15px;
position: fixed;
background-color: rgba(88, 88, 88, 0.9);
color : #FF0000;
text-align : center;
padding: 10px;
z-index : 9999;
border:2px solid black;
}
    `);
 
	document.getElementById("euForm").style.left = (200 || 20) + "px";
	document.getElementById("euForm").style.top = (200 || 100) + "px";
 
	function findAllLinks() {
		const allNodes = document.querySelectorAll('div.pgc-img > img');
		var objList = [];
		var i = 0;
		allNodes.forEach((item) => {
			const obj = {
				id: i++,
				url: item.src
			};
			objList.push(obj);
		});
		return objList;
	}
 
	var vm = new Vue({
		el: '#euForm',
		data: {
			version: "1.0.0",
		},
		methods: {
			async euDownAll() {
				var objList = findAllLinks();
				objList.forEach((item) => {
					const obj = {
						url: item.url,
						name: item.id + ".jpg",
						onload: function(e) {
 
						},
						onerror: function(e) {
							console.log(e)
						},
						onprogress: function(d) {
 
						}
					}
					GM_download(obj)
				});
			},
		}
	});
 
})();

refer to:
https://developer.mozilla.org/zh-CN/docs/Web/API/Document/querySelectorAll

Change Font Size in Win32 Rich Edit Control

	char* strFont = "Open Sans";
	int nFontSize = 70;
 
	CHARFORMAT cfFormat;
	memset(&cfFormat, 0, sizeof(cfFormat));
	cfFormat.cbSize = sizeof(cfFormat);
	cfFormat.dwMask = CFM_CHARSET | CFM_FACE | CFM_SIZE;
	cfFormat.bCharSet = ANSI_CHARSET;
	cfFormat.bPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
	cfFormat.yHeight = (nFontSize * 1440) / 72;
	strcpy(cfFormat.szFaceName, strFont);
 
	CHARRANGE cr;
	cr.cpMin = INT_MAX;
	cr.cpMax = INT_MAX;
	SendDlgItemMessage(m_hWnd, IDE_EDITBOX, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cfFormat);
	SendDlgItemMessage(m_hWnd, IDE_EDITBOX, EM_EXSETSEL, 0, (LPARAM)&cr);

refer to:
https://gamedev.net/forums/topic/457546-rich-edit-controls-change-the-font-size-win32-c/457546/

Change hyperlink color in QT

1
2
3
4
5
6
	// ui->btnEdit is a QLabel.
	ui->btnEdit->setText(QString("<a href=\"localhost\"><font color=\"#ff0000\">") + tr("Edit") + QString("</font></a>"));
	ui->btnEdit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
	connect(ui->btnEdit, &QLabel::linkActivated, [=, this](QString url) {
		...
	});

refer to:
https://www.lmlphp.com/user/507/article/item/13949