Notice
Recent Posts
Recent Comments
ยซ   2024/09   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

Spring: ํ™˜์ž ์ฝ”๋“œ๊ฐ€ null์ผ ๋•Œ ํ™˜์ž ์ฝ”๋“œ ์ฝ์–ด์„œ ๋‚ด์—ญ ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ์ฐฝ ๋„์šฐ๊ธฐ ๋ณธ๋ฌธ

๐Ÿ’ปBootcamp Self-Study Revisionโœจ/Spring, Spring Boot, Java, SQL

Spring: ํ™˜์ž ์ฝ”๋“œ๊ฐ€ null์ผ ๋•Œ ํ™˜์ž ์ฝ”๋“œ ์ฝ์–ด์„œ ๋‚ด์—ญ ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ์ฐฝ ๋„์šฐ๊ธฐ

yjyuwisely 2023. 5. 7. 01:15

ํ˜„์žฌ ํŒ€ ํ”„๋กœ์ ํŠธ 1๋กœ '์˜จ๋ผ์ธ ์ฆ๋ช…์„œ ์ถœ๋ ฅ ์›น์‚ฌ์ดํŠธ'๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐ

ํ™˜์ž ์ฝ”๋“œ๊ฐ€ ๊ฐ๊ฐ ๋ถ„๋ฅ˜๋๊ณ , ์‚ฌ์šฉ์ž๋Š” ํ™˜์ž ์ฝ”๋“œ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ ๊ฑฐ๊ธฐ์— ๋งž๋Š” ์ฆ๋ช…์„œ๋ฅผ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๊ณ ,
์‚ฌ์šฉ์ž๊ฐ€ ํ™˜์ž ์ฝ”๋“œ๊ฐ€ ์—†๋Š” ์ฆ๋ช…์„œ ๋ฐœ๊ธ‰ ์‹ ์ฒญ์„ ๋ˆ„๋ฅด๋ฉด ๋‚ด์—ญ์ด ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ์ฐฝ์ด ๋œฌ๋‹ค.

์•„๋ž˜์ฒ˜๋Ÿผ ์ž˜ ์ง„ํ–‰์ด ๋์—ˆ๋‹ค.


๊ทผ๋ฐ ์‚ฌ์šฉ์ž๊ฐ€ ํšŒ์› ๊ฐ€์ž… ํ›„ ๋กœ๊ทธ์ธ์„ ํ–ˆ์„ ๋•Œ ํ™˜์ž ์ฝ”๋“œ๊ฐ€ MySQL์—์„œ null์ด์—ˆ๋‹ค.

์ด์œ ๋Š” ์˜์‚ฌ๊ฐ€ ๊ทธ ์‚ฌ์šฉ์ž์˜ ์ง„๋‹จ์„œ๋ฅผ ์ž‘์„ฑํ•œ ์ ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. (๊ทธ๋ƒฅ ๋‹จ์ˆœํžˆ ํšŒ์›๊ฐ€์ž… ํ›„ ๋กœ๊ทธ์ธํ•œ ์ƒํ™ฉ์ด๋‹ค.)

์˜จ๋ผ์ธ ์ฆ๋ช…์„œ ๋ฐœ๊ธ‰ ์‹ ์ฒญ ํŽ˜์ด์ง€
๋‚ด์—ญ์ด ์—†์œผ๋ฉด ๋‚ด์—ญ์ด ์—†๋‹ค๋Š” ๊ฒฝ๊ณ ์ฐฝ์ด ๋– ์•ผํ•˜๋Š” ๋ฐ ์ฝ”๋“œ ์ˆ˜์ • ์ „์—๋Š” ์ € ์ƒํƒœ๊ฐ€ ์•ˆ ๋๋‹ค.



์šฐ์„  CertificateMapper.xml์—์„œ

๊ธฐ์กด์— ์“ฐ๋˜ inner join ๋Œ€์‹ ์— left join์„ ์“ด๋‹ค.

	<!-- Issue.jsp -->
	<select id="Issue" resultMap="MemberCertJoinVal">
		SELECT m.id, name, patientcode
		FROM member AS m
		LEFT JOIN certificate AS c <!-- patientcode: null ๊ฐ’๋„ ์žˆ์œผ๋ฏ€๋กœ LEFT JOIN์„ ์“ด๋‹ค.  -->
		<!-- ON: JOIN ์„ ํ•˜๊ธฐ ์ „ ํ•„ํ„ฐ๋ง -->
		ON m.id = c.id <!-- ๋™์ผ ์นผ๋Ÿผ: id  -->
		<!-- WHERE: JOIN ์„ ํ•œ ํ›„ ํ•„ํ„ฐ๋ง -->
		WHERE m.id = #{id}<!-- ๋กœ๊ทธ์ธํ•œ ์œ ์ €: the value of the id parameter that is passed to the SQL query at runtime -->
	</select>

Left join์„ ์“ด ํ›„ MySQL์˜ ๊ฒฐ๊ณผ) 

MySQL์—์„œ member ํ…Œ์ด๋ธ”์˜ patientcode๊ฐ€ NULL๊ฐ’์ด๋ผ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

์ฝ”๋“œ ์ˆ˜์ • ์ „, ๊ธฐ์กด Inner join์„ ์“ด ํ›„ MySQL์˜ ๊ฒฐ๊ณผ) 

๊ธฐ์กด์˜ inner join์„ ์“ฐ๋ฉด ํ…Œ์ด๋ธ”์—์„œ null๊ฐ’์„ ๊ฐ€์ง„ ์‚ฌ์šฉ์ž๊ฐ€ ์•ˆ ๋œฌ๋‹ค.


๊ทธ๋ฆฌ๊ณ  ๊ธฐ์กด์— ๋งŒ๋“ค์—ˆ๋˜ '๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค.' ๊ฒฝ๊ณ ์ฐฝ์„ ๋œจ๊ฒŒ ํ•˜๋Š” JSํŒŒ์ผ์„ ์ˆ˜์ •ํ–ˆ๋‹ค.

console.log("patientcode typeof:" + typeof patientcode);

๋ฅผ ์“ฐ๋ฉด์„œ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋ฅผ ํ†ตํ•ด ํ™˜์ž์ฝ”๋“œ(patientcode)ํƒ€์ž…์„ ์•Œ๊ฒŒ ๋๋Š”๋ฐ,

์•„๋ž˜์ฒ˜๋Ÿผ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ string ํƒ€์ž…์œผ๋กœ ๋–ด๋‹ค.

If the value is an empty string, then the above code will output 'string'.
If the value is
NULL, then it will output 'object'.


empty string์ธ ๊ฒฝ์šฐ string type์ด๋ผ๊ณ  ๋œจ๊ณ  null์ธ ๊ฒฝ์šฐ object type์ด๋ผ๊ณ  ๋œฌ๋‹ค.

๊ฐœ๋ฐœ์ž ๋„๊ตฌ์˜ ๊ฒฐ๊ณผ)

typeof:string์ด๋‹ค.

๊ทธ๋ž˜์„œ ๊ธฐ์กด์— ์กฐ๊ฑด์‹์—์„œ patientcode === null ์ด๋ฉด
๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค ๊ฒฝ๊ณ ์ฐฝ์„ ๋„์šฐ๊ฒŒ ํ–ˆ๋Š”๋ฐ, ๊ณ„์† ์ฝ”๋“œ๊ฐ€ ์•ˆ ๋˜๋Š” ๊ฑฐ์˜€๋‹ค.

string type์ด๋ฏ€๋กœ ์•„๋ž˜์ฒ˜๋Ÿผ ์ฝ”๋“œ๋ฅผ ๋‹ค์‹œ ์ˆ˜์ •ํ–ˆ๋‹ค.

patientcode.trim() === ''


trim() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด ์–‘ ๋์˜ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๊ณ  ์›๋ณธ ๋ฌธ์ž์—ด์„ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

์ˆ˜์ •ํ•œ issueAlert.js) 

console.log("Connect: Swal.fire()")

// Swal.fire ๊ฒฝ๊ณ ์ฐฝ ์ ์šฉ
patientcode = document.getElementById("patientcode").value;
console.log("patientcode:" + patientcode)
console.log("patientcode typeof:" + typeof patientcode);

// Once a constant is initialized, we cannot change its value
// const ๋ณ€์ˆ˜๋Š” ์—…๋ฐ์ดํŠธ์™€ ์žฌ์„ ์–ธ ๋‘˜ ๋‹ค ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.
const linkGeneral = document.getElementById("linkGeneral");	// ์ง„๋ฃŒํ™•์ธ์„œ 
const linkInout = document.getElementById("linkInout");	// ์ž…ํ‡ด์›ํ™•์ธ์„œ 
const linkSurg = document.getElementById("linkSurg");	// ์ˆ˜์ˆ ํ™•์ธ์„œ 

// ์ง„๋ฃŒํ™•์ธ์„œ
linkGeneral.addEventListener("click", clickGeneral);

function clickGeneral(e) {
	if (patientcode === '2' || patientcode === '3' || patientcode.trim() === '') {
		e.preventDefault(); //a ํƒœ๊ทธ๋‚˜ submit ํƒœ๊ทธ์˜ ๊ณ ์œ ์˜ ๋™์ž‘์„ ์ค‘๋‹จ
		Swal.fire('๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค.', '', 'error');
	}
	else {
		window.location.href = "javascript:GeneralRequest('${common.id}')";
		//window.location.href = "/GeneralDown?id=${common.id}";
	}
};

// ์ž…ํ‡ด์›ํ™•์ธ์„œ
linkInout.addEventListener("click", clickInout);
function clickInout(e) {
	if (patientcode === '1' || patientcode === '3' || patientcode.trim() === '') {
		e.preventDefault();
		Swal.fire('๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค.', '', 'error');
	}
	else {
		window.location.href = "javascript:InOutRequest('${common.id}')";
		//window.location.href = "/InoutDown?id=${common.id}";
	}
};

// ์ˆ˜์ˆ ํ™•์ธ์„œ
linkSurg.addEventListener("click", clickSurg);
function clickSurg(e) {
	console.log("Connect: linkSurg")
	if (patientcode === '1' || patientcode === '2' || patientcode.trim() === '') {
		e.preventDefault();
		Swal.fire('๋‚ด์—ญ์ด ์—†์Šต๋‹ˆ๋‹ค.', '', 'error');
	}
	else {
		window.location.href = href = "javascript:SergRequest('${common.id}')";
		//window.location.href = "/SergDown?id=${common.id}";
	}
};

๊ฒฐ๋ก ) ํ™˜์ž ์ฝ”๋“œ๊ฐ€ ์—†๋Š” ํšŒ์›์ด ์˜ฌ๋ผ์ธ ์ฆ๋ช…์„œ ๋ฐœ๊ธ‰ ์‹ ์ฒญ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ, ์ด์ œ ์•„๋ž˜์ฒ˜๋Ÿผ ๊ฒฝ๊ณ ์ฐฝ์ด ์ž˜ ๋œฌ๋‹ค.


728x90
๋ฐ˜์‘ํ˜•
Comments