상세 컨텐츠

본문 제목

spring 설정(2) controller, dao, service, serviceImpl, vo, mapper, mybatis

Framework/Spring

by H_Develop 2023. 3. 30. 16:18

본문

CONTROLLER

ViewController와 ManageController로 구분해 두었다.

페이지 접속은 ViewController를 통하며, 동적 작업은 ManageController를 통한다.

 

ViewController

@Controller
public class PD0010ViewController {

	@Resource(name = "PD0010Service")
	private PD0010Service PD0010Service;

	@RequestMapping(value = "/")
	public String index(Model model) throws Exception {


		return "PD0010/PD0010";
	}
	
}

ManageController

@Controller
public class PD0010ManageController {

	@Resource(name = "PD0010Service")
	private PD0010Service PD0010Service;
	
	@PostMapping(value = "/PD0010/list.do")
	@ResponseBody
	public ModelAndView selectList(@RequestBody PD0010VO vo, Model model) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("jsonView");

		List<PD0010VO> listOne = PD0010Service.getListOne(vo);
		mav.addObject("listOne", listOne);
		
		return mav;
	}
	
}

 

SERVICE

public interface PD0010Service {
	
	List<PD0010VO> getList() throws Exception;
	
	List<PD0010VO> getListOne(PD0010VO vo) throws Exception;
	
}

 

 

SERVICEIMPL

@Service("PD0010Service")
public class PD0010ServiceImpl implements PD0010Service{
	
	@Resource(name="PD0010Dao")
    private PD0010Dao PD0010Dao;

	@Override
	public List<PD0010VO> getList() throws Exception {
		return PD0010Dao.selectInfoList();
	}
	
	@Override
	public List<PD0010VO> getListOne(PD0010VO vo) throws Exception {
		List<PD0010VO> data = PD0010Dao.selectOneList(vo);
		System.out.println(data);
		return data;
	}
	
}

 

 

DAO

@Repository("PD0010Dao")
public class PD0010Dao {
	
	private static final String MAPPER_ID = "PD0010Dao";

	@Autowired
	private SqlSession sqlSession;

	public List<PD0010VO> selectInfoList() throws Exception {
		return sqlSession.selectList(MAPPER_ID + ".selectInfoList");
	}
	
	public List<PD0010VO> selectOneList(PD0010VO vo) throws Exception {
		return sqlSession.selectList(MAPPER_ID + ".selectOneList", vo);
	}
}

 

VO

@Getter
@Setter
public class PD0010VO {
	private String id;
	private String pw;
	private String manufacturer;
	private String unit;
	private String proNumber;
	private String beYn;
	private String useYn;
}

 

 

MAPPER

<?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="PD0010Dao">
	<select id="selectInfoList" parameterType="com.newlecture.web.vo.PD0010VO" resultType="com.newlecture.web.vo.PD0010VO">
		SELECT 
			*
		FROM 
			PD0010
	</select>
	<select id="selectOneList" parameterType="com.newlecture.web.vo.PD0010VO" resultType="com.newlecture.web.vo.PD0010VO">
		SELECT 
			*
		FROM 
			PD0010
		WHERE
			ID = #{id}
	</select>
</mapper>

 

 

MYBATIS

<?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>

	<settings>
        <setting name="cacheEnabled" value="false" />
        <setting name="jdbcTypeForNull" value="NULL" />
		<setting name="mapUnderscoreToCamelCase" value="true" />
	</settings>

</configuration>

 

 

관련글 더보기