java

JSP - ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ(11) - ์ฃผ์†Œ API ์‚ฌ์šฉํ•˜๊ธฐ

dev_summer 2020. 11. 12. 11:35

 

1. ํ…Œ์ด๋ธ” ์ˆ˜์ •

 

alter table user add address varchar(100);

 

 

 

2. User ๋ชจ๋ธ ์ˆ˜์ •

ํ–‰์„ ์ถ”๊ฐ€ํ•˜๊ณ  ๋ชจ๋ธ์„ ๋ฐ”๊ฟ”๋ฒ„๋ฆฌ๋ฉด ๋ชจ~๋“ ๊ฒƒ์„ ๋ฐ”๊ฟ”์•ผํ•จ. ์ด๊ฒƒ์„ ํ•ด๊ฒฐํ•˜๊ธฐ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋ฐ›์•„์•ผํ•œ๋‹ค.

(1).lombok ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋‹ค์šด : ๊ฒŒํ„ฐ์„ธํ„ฐ๋ฅผ ์ž๋™์œผ๋กœ ์ธ์‹์‹œ์ผœ์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

https://mvnrepository.com/artifact/org.projectlombok/lombok/1.18.8

 

Maven Repository: org.projectlombok » lombok » 1.18.8

Spice up your java: Automatic Resource Management, automatic generation of getters, setters, equals, hashCode and toString, and more! Note: There is a new version for this artifact org.projectlombok lombok 1.18.8 provided // https://mvnrepository.com/artif

mvnrepository.com

 

 

์„ ํ•ด์†Œํ•˜๊ธฐ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€

 

 

 

(2). ๋‹ค์šด ๋ฐ›์€ jarํŒŒ์ผ ์‹คํ–‰

์ดํด๋ฆฝ์Šค๊ฐ€ ์•Œ์•„๋จน๊ธฐ์œ„ํ•œ ๋ฐฉ๋ฒ•

ํ”„๋กœ์ ํŠธ๋Š” libํŒŒ์ผ์— ๋„ฃ์œผ๋ฉด ์•Œ์•„ ๋จน๋Š”๋ฐ ์ดํด๋ฆฝ์Šค ์ž์ฒด๋Š” ๋ชป์•Œ์•„ ๋จน๊ธฐ๋•Œ๋ฌธ์— ์ด๊ฒƒ์„ ์ธ์‹์‹œ์ผœ์ค˜์•ผํ•จ.

๋ฉ์ฒญ์ด ์ดํด๋ฆฝ์Šค ๊ฐ™์œผ๋‹ˆ๋ผ๊ณ 

specify location ํด๋ฆญ

 

 

 

 

(3) STS ์žฌ์‹คํ–‰

 

(4) board.model.User.java

 

package com.cos.board.model;

import java.sql.Timestamp;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

// model, vo(value object), bean(์ฝฉ)

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder

//์„ธํ„ฐ๋งŒ ํ•˜๊ณ ์‹ถ์œผ๋ฉด @Setter,@Getter @

public class User {
	private int id;
	private String username;
	private String password;
	private String email;
	private String address;
	private Timestamp createTime;
	
}

 

 

 

 

 

(5) BuilderTest.java

๋นŒ๋” ์ดํ•ดํ•˜๊ธฐ

 

package com.cos.board.test;


// 1.ํ•œ๋ฒˆ๊ฐ’์ด ์ •ํ•ด์ง€๋ฉด ์ˆ˜์ •์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.(๋นŒ๋” ๋งŒ๋“ค๋•Œ๋Š” ๊ฒŒํ„ฐ๋งŒ ์”€. ์Ž„ํ„ฐ๋Š” ์ตœ์ดˆ์— ์‚ฌ์šฉ)
// 2. ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ์— ์ˆœ์„œ๋ฅผ ์ง€ํ‚ฌ ํ•„์š”๊ฐ€ ์—†๋‹ค.
// 3. ์ˆœ์„œ๋ฅผ ์ง€ํ‚ค์ง€ ์•Š์•„๋„๋˜๋‹ˆ ๋•Œ๋ฌธ์— ์‹ค์ˆ˜๋ฅผ ์ค„์ž„
// 4. ํŒŒ๋ผ๋ฉ”ํ„ฐ์— ๊ฐฏ์ˆ˜๋ฅผ ์ง€ํ‚ค์ง€ ์•Š์•„๋„ ๋œ๋‹ค.(ํ•„๋“œ, ์†์„ฑ์˜ ์ถ”๊ฐ€๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค.

class Product{
	
	public String getName() {
		return name;
	}
	public int getPrice() {
		return price;
	}
	private String name;
	private int price;
	
	public Product(Builder builder) {
		this.name=builder.name;	
		this.price=builder.price;	
	}
	static class Builder{
		
		private String name;
		private int price;
		
		
		public Builder() {}
		
		public Builder name(String value) {
			this.name=value;
			return this;
			
		}
		
		public Builder price(int value) {
			this.price=value;
			return this;
			
		}
		
		
		
		public Product build() {
			return new Product(this);
		}
	}
}
public class builderTest {
	public static void main(String[] args) {
		
		Product p = new Product.Builder().name("์„œํ•˜").build();
		
		System.out.println(p.getName());
		System.out.println(p.getPrice());
		
	}
}

 

 

 

 

 

 

- textarea์˜ ์—๋””ํ„ฐ์ธ ์ธ๋จธ๋…ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ์œ„ํ•ด CDN(Contents Delivery Network) ๋งํฌ ์‚ฌ์šฉ

์•„๋ž˜์˜ summernote getting start์‚ฌ์šฉํ•˜๋ฉด ๋จ.

https://summernote.org/getting-started/

 

Summernote - Super Simple WYSIWYG editor

Get Summernote

summernote.org

 

 

 

 

- ๊ฒŒ์‹œํŒ๋งŒ๋“ค๊ธฐ ์ „ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ content๋ฅผ ์ €์žฅํ•  ํฌ๊ธฐ๋ฅผ ํ™•์ธํ•ด์•ผํ•œ๋‹ค.

 

๋Œ€ํ‘œ์‚ฌ์ง„ ์‚ญ์ œ

mysql ๊ฒŒ์‹œ๊ธ€์„ ์ €์žฅํ•˜๋Š” content์˜ ํฌ๊ธฐ ํ™•์ธํ•˜๊ธฐ

 

 

- DB ์กฐ์ธ ์‹œ ์ฐธ์กฐํ‚ค๊ฐ€ ์žˆ๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์กฐ์ธ ์‹œ ์•ž์œผ๋กœ ๋‘ฌ์•ผํ•จ.(์†๋„ ๋ฉด)

 

 

๋กฌ๋ถ์˜ ์žฅ์ 

1.ํ•œ๋ฒˆ๊ฐ’์ด ์ •ํ•ด์ง€๋ฉด ์ˆ˜์ •์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.(๋นŒ๋” ๋งŒ๋“ค๋•Œ๋Š” ๊ฒŒํ„ฐ๋งŒ ์”€. ์Ž„ํ„ฐ๋Š” ์ตœ์ดˆ์— ์‚ฌ์šฉ)

2. ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ์— ์ˆœ์„œ๋ฅผ ์ง€ํ‚ฌ ํ•„์š”๊ฐ€ ์—†๋‹ค.

3. ์ˆœ์„œ๋ฅผ ์ง€ํ‚ค์ง€ ์•Š์•„๋„๋˜๋‹ˆ ๋•Œ๋ฌธ์— ์‹ค์ˆ˜๋ฅผ ์ค„์ž„

4. ํŒŒ๋ผ๋ฉ”ํ„ฐ์— ๊ฐฏ์ˆ˜๋ฅผ ์ง€ํ‚ค์ง€ ์•Š์•„๋„ ๋œ๋‹ค.(ํ•„๋“œ, ์†์„ฑ์˜ ์ถ”๊ฐ€๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š๋Š”๋‹ค.

 

โ€‹

 

@Data(getter๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•œ๋‹ค.)
@AllArgsConstructor
@NoArgsConstructor
@Builder