전자정부프레임워크 1 - 기본 MVC

akanana·2023년 5월 22일
0

전자정부프레임워크를 통하여 가장 기본적인 MVC 패턴을 생성해보자

✔Controller

NiccController.java

package egovframework.example.cmmn.controller;
...
@Controller
public class NiccController {
	
	@Autowired
	private NiccService niccService;
	
	@GetMapping("/hello")
	public String goHello() {
		System.out.println("do hello");
		List<TestEntity> result = niccService.findAll();
		for (TestEntity testEntity : result) {
			System.out.println(testEntity);
		}
		
		return "hello";
	}
	@RequestMapping("/bye")
	public String goBye() {
		System.out.println("do bye");
		return "bye";
	}
}

✔Service

NiccService.java

package egovframework.example.cmmn.service;
...
public interface NiccService {

	public List<TestEntity> findAll();
}

NiccServiceImpl.java

package egovframework.example.cmmn.service;
...
@Service
public class NiccServiceImpl implements NiccService {

	@Autowired
	private TestDao testDao;

	@Override
	public List<TestEntity> findAll() {
		System.out.println("do hello service");
		List<TestEntity> result = null;
		try {
			result = testDao.findAll();
		} catch (Exception e) {
			System.out.println("e : "+e);
		}
		return result;
	}

}

✔Dao

TestDao.java

package egovframework.example.cmmn.dao;
...
@Mapper("testDao")
public interface TestDao {
	
	List<TestEntity> findAll() throws Exception;

}

✔Mapper

TestDao.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="egovframework.example.cmmn.dao.TestDao">

    <select id="findAll" resultType="egovframework.example.cmmn.model.TestEntity">
        select * from test
    </select>

</mapper>

0개의 댓글