암호화 3가지
공개키(비대칭키) SEED
비공개키(대칭키) RSA
해시키 (암호화)MD5 SHA256
->복호화X,
ORM
객체지향프로젝트를 RDB에 매핑시켜주는것
대표적인기술 : MyBatis(파셀 매핑), Jpa(풀매핑)
여기에 두개 걸어주기
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
implementation 'javax.servlet:jstl'
두개걸어주기
classpath는 resource이다
# view Resolver
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
# Mybatis
mybatis:
config-location: classpath:configuration.xml
mapper-locations: classpath:mappers/*.xml
package com.oracle.oBootMybatis01.model;
import lombok.Data;
@Data
public class Dept {
private int deptno;
private String dname;
private String loc;
}
package com.oracle.oBootMybatis01.model;
import lombok.Data;
@Data
public class Emp {
private int empno;
private String ename;
private String job;
private int mgr;
private String hiredate;
private int sal;
private int com;
private int deptno;
//조회용
private String search;
private String keyword;
private String pageNum;
private int start;
private int end;
}
인터페이스생성
package com.oracle.oBootMybatis01.dao;
public interface EmpDao {
int totalEmp();
}
EmpDao인터페이스상속받아 클래스 생성
package com.oracle.oBootMybatis01.dao;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import lombok.RequiredArgsConstructor;
@Repository
@RequiredArgsConstructor
public class EmpDaoImpl implements EmpDao {
//Mybatis DB 연동
private final SqlSession session;
@Override
public int totalEmp() {
int tot = 0 ;
System.out.println("EmpDaoImpl statr total . . . ");
return 0;
}
}
인터페이스
package com.oracle.oBootMybatis01.service;
public interface EmpService {
int totalEmp();
}
EmpService 인터페이스 상속
package com.oracle.oBootMybatis01.service;
import org.springframework.stereotype.Service;
import com.oracle.oBootMybatis01.dao.EmpDao;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class EmpServiceImpl implements EmpService {
private final EmpDao ed;
@Override
public int totalEmp() {
System.out.println("EmpServiceImpl Start total. . . . .");
return 0;
}
}
package com.oracle.oBootMybatis01.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import com.oracle.oBootMybatis01.model.Emp;
import com.oracle.oBootMybatis01.service.EmpService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Controller
@RequiredArgsConstructor
@Slf4j
public class EmpController {
private final EmpService es;
@RequestMapping(value="listEmp") //listEmp 걸면 내가 떠오른다
//empList조회 --> Emp ,페이지 , 모델을 데리고 조회
public String empList(Emp emp , String currentPage, Model model) {
System.out.println("EmpController Start listEmp. . . . ");
return "list";
}
}
▶Security때문에 제공해주는 화면뜸 -->SecurityCOnfig 걸어주기 -->무시하고 내가 지정해준 페이지 나옴
package com.oracle.oBootMybatis01.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
//제일먼저 실행
@Configuration //Ioc 빈(Bean) 을 등록
@EnableWebSecurity //필터 체인 관리 시작 어노테이션
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) //특정주소 접근시 권한 및 인가
public class SecurityConfig {
@Bean //비밀번호 암호화
public BCryptPasswordEncoder encodePwd() {
return new BCryptPasswordEncoder();
}
//
@Bean
protected SecurityFilterChain securityFilterChain (HttpSecurity http) throws Exception {
http.csrf().disable(); //가로채기 비활성화
http.authorizeHttpRequests() //인가된
.anyRequest() //어느누구나
.permitAll(); //접근할수 있다
return http.build();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>입성 성공 </h1>
</body>
</html>
🔽 한바퀴 돌아가는지 확인 완료
🔽추가 코딩하기
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="Emp" type="com.oracle.oBootMybatis01.model.Emp"/>
<typeAlias alias="Dept" type="com.oracle.oBootMybatis01.model.Dept"/>
</typeAliases>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.oracle.oBootMybatis01.EmpMapper">
<select id="empTotal" resultType="int">
select Count(*)From emp
</select>
</mapper>
🔽 한바퀴 돌아가는지 확인완료후->실제 코딩
@Controller
@RequiredArgsConstructor
@Slf4j
public class EmpController {
private final EmpService es;
@RequestMapping(value="listEmp") //listEmp 걸면 내가 떠오른다
//empList조회 --> Emp ,페이지 , 모델을 데리고 조회
public String empList(Emp emp , String currentPage, Model model) {
System.out.println("EmpController Start listEmp. . . . ");
int totalEmp = es.totalEmp(); //토탈이엠피 가지고옴
log.info("EmpController totalEmp->{}", totalEmp);
model.addAttribute("totalEmp", totalEmp );
return "list";
}
}
package com.oracle.oBootMybatis01.service;
import org.springframework.stereotype.Service;
import com.oracle.oBootMybatis01.dao.EmpDao;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
public class EmpServiceImpl implements EmpService {
private final EmpDao ed;
@Override
public int totalEmp() {
System.out.println("EmpServiceImpl Start total. . . . .");
int totEmpCnt = ed.totalEmp();
log.info(" EmpServiceImpl totalEmp totEmpCnt->{}",totEmpCnt);
return totEmpCnt;
}
}
package com.oracle.oBootMybatis01.dao;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import lombok.RequiredArgsConstructor;
@Repository
@RequiredArgsConstructor
public class EmpDaoImpl implements EmpDao {
//Mybatis DB 연동
private final SqlSession session;
@Override
public int totalEmp() {
int totEmpCount = 0 ;
System.out.println("EmpDaoImpl statr total . . . ");
try {
totEmpCount = session.selectOne("empTotal");
System.out.println("EmpDaoImpl totalEmp totEmpCount-> "+totEmpCount);
} catch (Exception e) {
System.out.println("EmpDaoImpl totalEmp Exception Exception-> "+e.getMessage());
}
;
return totEmpCount;
}
}
package com.oracle.oBootMybatis01.service;
import org.springframework.stereotype.Service;
import com.oracle.oBootMybatis01.dao.EmpDao;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
public class EmpServiceImpl implements EmpService {
private final EmpDao ed;
@Override
public int totalEmp() {
System.out.println("EmpServiceImpl Start total. . . . .");
int totEmpCnt = ed.totalEmp();
log.info(" EmpServiceImpl totalEmp totEmpCnt->{}",totEmpCnt);
return totEmpCnt;
}
}
<h5> 사원수 : ${totalEmp}</h5>
🔽 토탈수세기 완
emp.setStart(1); //시작시 1
emp.setEnd(2); //시작시 2
List<Emp> listEmp = es.listEmp(emp);
List<Emp> listEmp(Emp emp);
@Override
public List<Emp> listEmp(Emp emp) {
List<Emp> empList = null;
System.out.println(" EmpServiceImpl listManager Start . . . ");
empList = ed.listEmp(emp);
System.out.println("EmpServiceImpl listEmp empList.size()->"+empList.size() );
return empList;
}
List<Emp> listEmp(Emp emp);
@Override
public List<Emp> listEmp(Emp emp) {
//select one , selectList
List<Emp> empList = null;
System.out.println("EmpDaoImpl listEmp Start . . ..");
empList =
//Map id parameter
session.selectList("tkEmpListAll", emp);
return null;
}
SELECT Count(*) FROM emp //앞에 이름 이니셜 해주면편함 tk select * from ( select rownum rn, a.* from (select * from emp order by empno) a ) where rn BETWEEN #{start} and #{end} ```파라메터 넣는법 --> #{값}
<?xml version="1.0" encoding="UTF-8" ?>
하나만 조회하면 selectone , 많이조회하면 selectList
@Override
public List<Emp> listEmp(Emp emp) {
//하나만 조회하면 selectone , 많이조회하면 selectList
List<Emp> empList = null;
System.out.println("EmpDaoImpl listEmp Start . . ..");
try {
//Map id parameter
empList = session.selectList("tkEmpListAll", emp);
System.out.println("EmpDaoImpl listEmp empList.size()-> "+empList.size() );
} catch (Exception e) {
System.out.println("EmpDaoImpl listEmp e.getMessage()-> "+e.getMessage() );
}
return empList;
}
model.addAttribute("listEmp", listEmp );
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias alias="Emp" type="com.oracle.oBootMybatis01.model.Emp"/>
<typeAlias alias="Dept" type="com.oracle.oBootMybatis01.model.Dept"/>
</typeAliases>
</configuration>
<table>
<tr><th>번호 </th><th>사번 </th><th>이름 </th><th>업무 </th><th>급여 </th></tr>
<c:forEach var="emp" items="${listEmp }" >
<tr><td>${num }</td> <td>${emp.empno }</td>
<td><a href="detail?empno=${emp.empno }">${emp.ename }</a></td>
<td>${emp.job }</td> <td>${emp.sal }</td></tr>
<c:set var="num" value="${num - 1 }"></c:set>
</c:forEach>
</table>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<link href="css/board.css" rel="stylesheet" type="text/css">
🔽전체목록 불러오기 완