<aside> ๐ก
ํ์๊ด๋ฆฌ
<aside> ๐ก
๊ธฐ๋ณธ์ค์
JAVA_HOME ํ๊ฒฝ๋ณ์์ jdk-xx ๊ฒฝ๋ก๋ฑ๋ก โ cmd > java -version ํ์ธ
IDE๊ณ ๋ฅด๊ณ ํ๋ก์ ํธ๋ด ์ํฌ์คํ์ด์ค์ค์
์ํฌ์คํ์ด์ค settings๋ฑ์ ํตํด UTF8์ ์ฉ ํ์ (๊ธฐ๋ณธ + html + css + jsp)
"settings": {
"files.encoding": "utf8"
} // IDE์ ๋ฐ๋ผ html + css + jsp ๋ณ๋ ์ฑ๊ฒจ์ผํ ์๋
Maven(์ค๋๋จ, ์์ ์ฑ ๋์) / Gradle(์๋๋ก์ด๋๋์, ๋์ธ)
Eclipse
Vscode
[plug] Java Extension Pack (JaveEE, Gradle, Maven)
[plug] Language support for Java (intelliSense)
[plug] Lombok Annotations Support for VS Code
build.gradle ์์กด์ฑ์ถ๊ฐ
configurations {
...
compileOnly {
extendsFrom annotationProcessor
}
}
dependencies {
...
/*Lombock-start*/
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
/*Lombock-end*/
}
settings.json ์๋ฐ๋ญ๊ท์ง์๋ฒ๋ฑ๋ก
// ํ๋ก์ ํธ๋ด AddFolderToWorkspace -> .vscodeํด๋์ถ๊ฐ -> settings.json
{
...
"java.jdt.ls.vmargs": "-javaagent:/path/to/lombok.jar"
}
[plug]
[plug]
[plug]
</aside>
[๋ชจ๋ Dependency] // 24.11.20.now
[์ฃผ์ Package]
import org.springframework.stereotype
//์ ๋
ธํ
์ด์
, component์ค์บ/bean๋ฑ๋ก ์ง์ ex: @Component, @Repository, @Service, @Controller
import org.springframework.context.ApplicationContext;
//์ ํ๋ฆฌ์ผ์ด์
์ปจํ
์คํธ ํฌํจ, bean๊ตฌ์ฑ๊ด๋ฆฌ
import org.springframework.beans.factory.annotation.Autowired;
//Bean๊ด๋ฆฌ/์์กด์ฑ ์ฃผ์
์ง์
import org.springframework.core.io.Resource;
//์ฝ์ด์ ํธ/๊ณตํต๊ธฐ๋ฅ ์ ๊ณต
import org.springframework.aop.framework.ProxyFactory;
//AOP(Aspect-Oriented Programming) ๊ธฐ๋ฅ์ ๊ณต
import org.springfamework.jdbc.core.JdbcTemplate;
//๊ฐํธํ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ ๊ทผ์ ์ํ JDBC ์ถ์ํ ๊ณ์ธต ์ ๊ณต
import org.springframework.transaction.annotation.Transactional;
//ํธ๋์ญ์
๊ด๋ฆฌ ์ง์
import org.springframework.web.bind.annotation.RequestMapping;
//์น ์ ํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐ ์ง์
import org.springframework.security.core.userdetails.UserDetailsService;
//๋ณด์ ๊ด๋ จ ๊ธฐ๋ฅ ์ ๊ณต
import org.springframework.boot.SpringApplication;
//์ ํ๋ฆฌ์ผ์ด์
์ ์ค์ /์คํ์ ๋๋ Spring Boot ์ง์
<aside> ๐
[ ์ฃผ์ ์ด๋ ธํ ์ด์ ๊ณผ ์๋์๋ฆฌ ]
@Controller โ @Service โ @Repository +@Component โ @autowired(DI)
@SpringBootApplication : ์คํ๋งMVC๋ ๊ฑฐ๋ํ switch()๋ฌธ ์๋ก ํ๋ ์์ํฌ๋ค์ด ๊ทธ๋ ๋ฏ ์คํ๋งMVC์ main()ํ๋ก์ธ์ค + ๋ฃจํ๊ตฌ์กฐ๋ฅผ ์ด์ฉํ ์ง์๋์์ ํ๋ ์์ํฌ ์๋๋ก ์๋ํ ์ํ, ๊ฐ๋ฐ์๋ ์คํ๋ง์ ๊ฑฐ๋ํ switch()๋ฌธ์ด๋ผ๊ณ ๋ณด๊ณ ๊ฐ๋ฐ์ ํ๊ฒ ๋จ
@Controller (ํด๋์ค) / @GetMapping (๋ฉ์๋) ์ด ์ค์์น๋ฌธ์ View์์ ์ธ๋ถ์ฌ์ฉ์๊ฐ ๋ชจ๋ ์ปจํธ๋กค(HTML์ ํน์ URLํํ์ ์ธ์)์ ๋ณด๋ธ๋ค ๊ฐ์ -์ค๊ณ๋จ,
์ด๊ฑธ ์ฒ๋ฆฌํ๊ธฐ์ํ ํด๋์ค๋ฅผ ํน๋ณํ @Controller๋ก ์ง์ ํด์ฃผ๋ฉด, ๋ฏธ๋ฆฌ ์ฝ์๋ ๊ด๋ จ ๋ฐ์ดํฐํด๋์ค์ ์ธ์คํด์ค๋ฅผ ์์ฑํ์ฌ ์คํ๋ง์ด ์ฑ๊ธํค์ผ๋ก ๊ด๋ฆฌํ๊ณ , ํด๋น ํด๋์ค์ ๋งด๋ฒํจ์์ค์ ํด๋น ํ์ ์ ๊ฐ์ฒด๊ฐ ํ์ํ ํจ์๊ฐ ์๋ ๊ฒฝ์ฐ, ํจ์๊ฐ ์คํ๋๋ ์ํฉ์์ ์๋์ผ๋ก ๊ฐ์ฒด๋ฅผ ์ธํํด์ค๋ค. (์์กด์ฑ์ฃผ์ DI : ์๋์ค๋ช ..)
๊ทธ๋ฆฌ๊ณ ์ด View๋ค์ ๋ฌธ์์ด์ ๊ณ ์ ์ฃผ์๋ก ๊ตฌ๋ถ๋๋ฉฐ, @GetMapping("๋์์ฃผ์") ์ด๋ ธํ ์ด์ ์ผ๋ก ํด๋น ์ปจํธ๋กค๊ณผ ๋งคํ๋ ๋ฉ์๋๋ฅผ ์ง์ ํจ
@Component (ํ์ ํด๋์ค) / @Service (ํ์ ํด๋์ค-๋น์ฆ๋์ค๋ก์งํนํ) Model๋ฑ๊ณผ ๊ฐ์ด ๋ฏธ๋ฆฌ์ ์๋ ํ์ ์ด ์๋ ์ปค์คํ ํ์ ์ ์์กด์ฑ์ฃผ์ ์ ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด, @Component,@Service์ด๋ ธํ ์ด์ ์ ์ด์ฉํด bean(์คํ๋ง์ ๋ฑ๋ก๋ ํ์ ์ ๊ด๋ฆฌ ๊ฐ์ฒด)์ผ๋ก ๋ฑ๋ก์ ์ ๋
@Repository
์์ฝ: ํฌ๊ฒ ๋ณด๋ฉด, View์ ๊ฐ๋ณ์ฃผ์์ ๋์ํ Controllerํด๋์ค์ ํ์์Mapping๋ฉ์๋๋ค์ ์ ์ธํด๋๋ฉด, ์คํ๋ง์ด ์์์ ์คํํ ์ง๋ง์ง ๊ด๋ฆฌ, ๊ฐ๋ฐ์์ ์ง์ ์ ์ธ ํ๋ก์ธ์ฑ์ ์๋ค. โ ๊ฑฐ๋ switch๋ฌธ ๋๋
๋ํ, Model์ ํด๋นํ๋ ์ฃผ์ ๋ฐ์ดํฐํด๋์ค ๋ํ Controller-Model๊ณผ ๊ฐ์ด ์ฌ์ ์ค๋น๋ ๊ฒ๋ค์ด ์์ด, ๊ฐ๋ฐ์๋ ์ค๊ณ/์ ์ธํ์ง ์๊ณ , ํ์๋งค๊ฐ๋ณ์๋ก ์ง์ ํ๊ธฐ๋งํ๋ฉด, ์ฌ์ฉ ๋ฐ ๊ด๋ฆฌ๋ ์คํ๋ง์ด ์์์ ํจ. โ ๊ฒฐ๊ตญ MVC์ ๋ผ๋์ค์์ ๊ฐ๋ฐ์๊ฐ ๊ฐ๋ฐํด์ผํ๋ ๊ฒ์ ์๋ค;;; V์ C์ ๋ด์ฉ ๊ทธ๋ฆฌ๊ณ custom-M ๋ฟ... (+ HTML์ ์ฌ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ฏ๋ก ์ค์ ๋ก๋ 1:1๋งคํ์ด ์๋, 1์ฃผ์:์ฌ๋ฌ๋งคํ ๊ตฌ์กฐ๊ฐ ๋จ)
โ ์์กด์ฑ์ฃผ์ DI: ์ ์ธํ์ ์๋ ํ์ ์ด์ง๋ง ํ์๋งค๊ฐ๋ณ์ ์ ์ธ์ด ๊ฐ๋ฅํ๊ณ , ์์ฑํ์ ์๋ ๊ฐ์ฒด์ด์ง๋ง, @์ปจํธ๋กค๋ฌ์ ์ํด ๊ด๋ จ ๊ฐ์ฒด๊ฐ ์๋์ผ๋ก ์์ฑ๋์ด ๊ด๋ฆฌ๋๊ณ , ์คํํ์ ์๋ ํจ์์ด์ง๋ง, @์ปจํธ๋กค๋ฌ์ ์ํด ์๋์คํ๋ ํจ์์, @GetMappingํ์์๋ฟ, ๋ช ์์ ์ผ๋ก ์ธํํ์ ์๋๋ฐ ์ค์ ๊ฐ์ฒด๊ฐ ์ธ์๋ก ์ฌ์ฉ๋๋ ๊ฒ
</aside>
[ default-bean s ]
<Model> : InterfaceClass๊ฐ์ฒดํ์
for ๋ทฐ์ ๋ฐ์ดํฐ์ ๋ฌ
public class ExtendedModelMap extends ConcurrentHashMap<String, Object> implements Model {
// HashMap์ ์์๋ฐ์ ModelMap์ Model์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๊ณ ์์
// ์ค์ model ๋ฉ์๋ ๋ฐ ๊ตฌํ์ ModelMap์์
}
public: //๋งด๋ฒํจ์.. +์ธํฐํ์ด์ค๋ ๋งด๋ฒ๋ณ์๋ ์๋ค
.addAttribute(String key, Object value) : ๋ชจ๋ธ์ ์์ฑ์ถ๊ฐ
.addAttribute(Object value) : ๋ชจ๋ธ์ ์ด๋ฆ์๋ ์์ฑ์ถ๊ฐ
.addAllAttributes(Map<String, ?> elements) : ๋ชจ๋ธ์ ์ฌ๋ฌ์์ฑ ์ผ๊ด์ถ๊ฐ by Map
.addAllAttributes(Collection<?> elements) : ๋ชจ๋ธ์ ์ฌ๋ฌ์์ฑ ์ผ๊ด์ถ๊ฐ by Collection
.mergeAttributes(Map<String, ?> elements) : ๋ชจ๋ธ์ ์ฃผ์ด์ง ์์ฑ ์ผ๊ด์ถ๊ฐ in Map
.containAtrribute(String key) : ๋ชจ๋ธ์ ํน์ ์์ฑ ์กฐํ
.asMap() : ๋ชจ๋ธ์ ๋ชจ๋ ์์ฑ ๋ฐํ to Map
<HttpServletRequest> : InterfaceClass๊ฐ์ฒดํ์
for HTTP์์ฒญ
.getParameter(String key) : ์์ฒญํ๋ผ๋ฏธํฐ ๊ฐ ๊ฐ์ ธ์ด
.getSession() : ์ธ์
๊ฐ์ฒด ๋ฐํ
.getAttributes(String key) : ์์ฒญ ์์ฑ ๊ฐ์ ธ์ด
<HttpServletResponse> : InterfaceClass๊ฐ์ฒดํ์
for HTTP์๋ต
.setStatus(ins sc) : HTTP์๋ต์ํ์ฝ๋ ์ค์
.addHeader(String key, String value) : ์๋ตํค๋ ์ถ๊ฐ
.getWriter() : ์๋ต๋ฐ์ดํฐ ์ฐ๊ธฐ์ํ PrintWriter๊ฐ์ฒด ๋ฐํ
<Principal> : InterfaceClass๊ฐ์ฒดํ์
for ์ธ์ฆ์ฌ์ฉ์์ ๋ณด
.getName() : ์ฌ์ฉ์ ์ด๋ฆ ๋ฐํ
<SessionState> : InterfaceClass๊ฐ์ฒดํ์
for ์ธ์
์๋ฃ์ํ
.setComplete() : ์ธ์
์๋ฃ์ํ ์ค์
<Locale> : InterfaceClass๊ฐ์ฒดํ์
for ๋ก์ผ์ผ์ ๋ณด
.getLanguage() : ์ธ์ด์ฝ๋ ๋ฐํ
.getCountry() : ๊ตญ๊ฐ์ฝ๋ ๋ฐํ