# 서버 자동 재시작
server.servlet.jsp.init-parameters.development=true
👀 sts에 oracle 연결 후 실제 data 받아서 저장해보기
- member_dto.java
package kr.co.sen;
import org.springframework.stereotype.Repository;
import lombok.Data;
@Data
@Repository("member_dto")
public class member_dto {
Integer midx,mage;
String mid,mpass,mname,mtel,memail,mgender;
}
- wepapp/join.jsp
<body>
<form id="frm" method="post" action="./joinok.do">
아이디 : <input type="text" name="mid"><br>
패스워드 : <input type="password" name="mpass"><br>
고객명 : <input type="text" name="mname"><br>
전화번호 : <input type="text" name="mtel"><br>
이메일 : <input type="text" name="memail"><br>
나이 : <input type="text" name="mage" maxlength="2"><br>
성별 : <label><input type="radio" value="M" name="mgender">남성</label>
<label><input type="radio" value="W" name="mgender" checked>여성</label> <br><br>
<button type="button" onclick="joinok()">회원가입</button>
</form>
</body>
- member_repo.java (interface)
package kr.co.sen;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface member_repo {
int join(member_dto mdto);
}
- resources/mapper/mapper.xml 수정
<?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="kr.co.sen.member_repo">
<insert id="join">
insert into member values (autono.nextval,#{mid},#{mname},#{mtel},#{memail},#{mage},#{mgender},#{mpass})
</insert>
</mapper>
순서 주의 - desc 했을때 순서랑 동일해야함
- member_service.java (interface)
package kr.co.sen;
public interface member_service {
public int join_member(member_dto mdto);
}
- memberServiceImpl.class
package kr.co.sen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class memberServiceImpl implements member_service{
@Autowired
private member_repo member_repo;
@Override
public int join_member(member_dto mdto) {
int result = member_repo.join(mdto);
return result;
}
}
- controller
PrintWriter pw = null;
@Resource(name="member_dto")
member_dto mdto;
@Autowired
private member_service member_service;
@PostMapping("/joinok.do")
public String joinok(@ModelAttribute member_dto mdto, ServletResponse res) {
res.setContentType("text/html;charset=utf-8");
int result = member_service.join_member(mdto);
try {
this.pw = res.getWriter();
if(result > 0) {
this.pw.write("<script>"
+ "alert('회원가입이 완료되었습니다.');"
+ "location.href='/login.do';"
+ "</script>");
}else {
this.pw.write("<script>"
+ "alert('쿼리 오류발생');"
+ "location.href='/login.do';"
+ "</script>");
}
}catch(Exception e){
System.out.println(e);
}finally {
this.pw.close();
}
return null;
}
** application.properteis에 mybatis 주석 풀려있어야함
#mybatis
mybatis.type-aliases-package=kr.co.sen
mybatis.mapper-locations=classpath:/mapper/*.xml
https://dev-eunse.tistory.com/265
여기 확인해보셈
'CLASS > SPRINGBOOT' 카테고리의 다른 글
#QR (1) | 2024.10.21 |
---|---|
#5-1 / websocket 통신... (1) | 2024.09.26 |
#1-1 / 🌸 Gradle Project start + Oracle (0) | 2024.08.30 |
#11-1 / websocket - socket 통신 (0) | 2024.08.29 |
#10-3 / Ajax로 이미지 전송 및 JPA => 삭제 (0) | 2024.08.29 |