728x90
반응형
아래의 설정 정보는 아래 포스팅을 참고하세요!
- Maven pom 설정 - pom.xml
/src/main/resource/application.properties
# port setting
server.port=7777
# dbcp setting
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@127.0.0.1:1521:xe
spring.datasource.username=scott
spring.datasource.password=tiger
#view resolver
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.devtools.livereload.enabled=true
#log level setting
logging.level.root=ERROR
# mybatis setting
mybatis.type-aliases-package=org.kosta.model.vo
/src/main/webapp/WEB-INF/views
View
/index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>HOME</title>
</head>
<body>
Hello SpringBoot <br><br>
<a href="find-member-form.do">회원검색</a>
</body>
</html>
/find-member-form.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원 검색 폼</title>
</head>
<body>
<h3>회원 검색 폼</h3>
<form action="findMemberById.do">
아이디 <input type="text" name="id"><br>
<input type="submit" value="검색">
</form>
</body>
</html>
/find-member-result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h3>회원검색 결과</h3>
${mvo}
</body>
</html>
MyBatis Proxy 설정 !
/src/main/resource/org.kosta.myproject.model
/MemberMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Sql Mapper -->
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.kosta.myapp.model.MemberMapper">
<select id="findMemberById" resultType="memberVO">
SELECT id,password, name, address
FROM spring_member
WHERE id=#{value}
</select>
</mapper>
src/main/java/org.kosta.myproject.model
/MemberMapper.java<<interface>>
package org.kosta.myapp.model;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MemberMapper {
public MemberVO findMemberById(String id);
}
Model
/src/main/java/org.kosta.myproject.model.vo
/MemberVO.java
package org.kosta.springmvc12.model.vo;
public class MemberVO {
private String id;
private String password;
private String name;
private String address;
public MemberVO() {
super();
// TODO Auto-generated constructor stub
}
public MemberVO(String id, String password, String name, String address) {
super();
this.id = id;
this.password = password;
this.name = name;
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "MemberVO [id=" + id + ", password=" + password + ", name=" + name + ", address=" + address + "]";
}
}
Controller
/src/main/java/org.kosta.myproject.controller
/HomeController.java
package org.kosta.myapp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping(value={"index.do","/"}) //<welcome-file> 설정
public String home() {
return "index";
}
}
/MemberController.java
package org.kosta.myapp.controller;
import javax.annotation.Resource;
import org.kosta.myapp.model.MemberMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class MemberController {
@Resource
private MemberMapper memberMapper;
@RequestMapping("find-member-form.do")
public String findMemberForm() {
return "find-member-form";
}
@RequestMapping("findMemberById.do")
public String findMemberById(String id, Model model) {
model.addAttribute("mvo", memberMapper.findMemberById(id));
return "find-member-result";
}
}
Test - 단위 테스트
/src/test/java/org.kosta.myapp
/Springboot1ApplicationTests.java
package org.kosta.myapp;
import javax.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.kosta.myapp.model.MemberMapper;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class Springboot1ApplicationTests {
@Resource
private MemberMapper mm;
@Test
void contextLoads() {
System.out.println(mm.findMemberById("java"));
//MemberVO [id=java, pasword=null, name=아이유, address=판교]
}
}
[ Browser 결과 화면 ]
1. index.jsp <welcome-file> 화면
2. '회원검색' 클릭
3. '회원검색' 결과
728x90
반응형
'Java Web Programming > 6. Spring | MyBatis' 카테고리의 다른 글
[Spring/MyBatis] Tiles Framework (스프링 타일즈) 환경 설정 (0) | 2020.11.18 |
---|---|
[SpringBoot] 스프링부트 환경설정 (2) | 2020.11.17 |
[SpringMVC/MyBatis] Transaction(트랜잭션) 적용 (회원관리) (0) | 2020.11.17 |
[SpringMVC/MyBatis] 회원 게시판 어플리케이션 구현 (Paging 페이징) (0) | 2020.11.16 |
[SpringMVC/MyBatis] 마이바티스에도 Proxy(프록시)를 적용해보자! (0) | 2020.11.16 |