Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Total
관리 메뉴

학습기록남기기

2022_06_16_Spring_10일 본문

수업_정리

2022_06_16_Spring_10일

backend_na 2022. 6. 16. 22:46

Spring

<context:component-scan base-package="com.spring.~~~"/>

-->@Component, @Controller , @Service ,@Repository 이 붙은 클래스를 빈으로 등록 

@RequestMapping("/spring") : get, post 둘다 허용 
@RequestMapping(value="/spring/get",method=RequestMethod.GET)
@RequestMapping(value="/spring/post",method=RequestMethod.POST)

Controller 화면 처리 
public void method() {}   : 요청 URL의 경로를 파일의 이름으로 사용
public String method () { return "re";} : view폴더 아래 re.jsp 파일로 이동
public String method() { return "redirect:/spring"} : /Spring URL로 요청
@ResposeBody  : 리턴값을 호출한(클라이언트)로 결과 리턴  :비동기 통신

요청 파라미터 처리
public param(HttpServletRequest request)  : int a=request.getParamaeter("태그 name이름")
public param(@RequestParam("태그 name이름") int a  : 이게 FM이나  태그name과 a가 일치하면 생략
public param (VO v)

Model : 화면에 데이터 전달하기 위한 객체
Model객체   : public param(Model model){  model.addattribute("key","value") } 

ModelAndVIew객체   :public ModelAndView param() { ModelAndView mv=new ModelAndView();
mv.addObject("key","value");   mv.setViewName("이동할 jsp"); reutrn mv;}

@ModelAttribute :public param(@ModelAttribute(num) int test, int year) {}
:화면에 바로 전달

RedirectArrtibutes :public param(RedirectAttribute ra) {   
ra.addFlashAttribute("key","value")}

root-context.xml 
<mybatis-spring:scan base-package="com.spring.db.repository"/>
mapper.xml 
DB컬럼명과 객체의 변수명이일치하지 않으면
<resultMap type= "객체 패키지명 " id="이름">
	<id property="변수명" column="DB컬럼명" />  :PRIMARY KEY
	<result property="변수명" column="DB컬럼명"/>	 :나머지
</resultMap>

메서드의 리턴타입이 존재할떄 컬럼명과 DB명 일치하지 않아도 상관없으면 ,
< select id="메서드명"   resultType="int" > 이런식으로 적는다 

<select id=" "   resultMap=" " >  :상관있으면 resultMa기입

@PathVariable(num) int boardNo :FM  , num과 boardNo의 이름이 동일하면 ()괄호 생략가능
@GetMapping("/content/{boardNo}")   // /content/{boardNo} 의 URL로 요청이 들어온다는 의미(이름은 아무렇게나 지어도 된다)
public String content(@PathVariable int boardNo, Model model, 
			@ModelAttribute("p") SearchVO search) {

param(@RequestBody VO v) : JSON데이터를 자바VO클래스 로 변환

 

Session

//서버에서 세션 객체를 얻는 방법
1.HttpServlerRequest 객체 사용    메서드의 매개변수로
public pram(HttpServletRequest request)
HttpSession session=request.getSession();  //JSP에서 사용하던 방법
session.setAttribute
///기존의 스프링메서드를 오버라이딩하는 경우가 생길 수 있어 , 이 방법을 알아둬야 한다 !!!!!!!!!!!!!!
		
//2.매가 값으로 HttpSession session 객체 받아서 사용 
public param(HttpSession session)
session.setAttribute

암호화

BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
String securePw=encoder.encode(user.getPassword());
System.out.println("암호화 후 비밀번호 : "+securePw);
		
user.setPassword(securePw);

'수업_정리' 카테고리의 다른 글

2022_06_20_Spring_12일  (0) 2022.06.20
2022_06_17_Spring_11일  (0) 2022.06.17
2022_06_15_Srping_9일  (0) 2022.06.15
2022_06_14_Spring_8일  (0) 2022.06.14
2022_06_13_Srping_7일  (0) 2022.06.13