전자정부프레임워크를 통하여 가장 기본적인 MVC 패턴을 생성해보자
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";
}
}
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;
}
}
TestDao.java
package egovframework.example.cmmn.dao;
...
@Mapper("testDao")
public interface TestDao {
List<TestEntity> findAll() throws Exception;
}
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>