getting started spring mvc with DD(Deployment Descriptor) ver2.5
- create a new project with Dynamic Web Project (DD ver2.5).
- convert project to maven. (right click on Project -> Configure)
- add Spring Project Nature. (right click on Project -> Spring Tools)
- add dependencies in pom.xml
- create spring configuration files.
- update your DD file with condition #5.
- create java, jsp files.
- run with tomcat
getting started with mybatis on this project
- add mybatis, mybatis-spring, spring-jdbc, mysql dependencies on pom.xml
<dependency> <groupId>org.mybatis </groupId> <artifactId>mybatis </artifactId> <version>3.4.2 </version> </dependency> <dependency> <groupId>org.mybatis </groupId> <artifactId>mybatis-spring </artifactId> <version>1.3.0 </version> </dependency> <dependency> <groupId>org.springframework </groupId> <artifactId>spring-jdbc </artifactId> <version>4.1.0.RELEASE </version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.44</version> </dependency>
- add xmlns: context and xsi:schemaLocation about spring-beans, spring-context on spring-controller.xml file
- add <context:annotation-config/> and beans (datasource, sqlSesscionFactory, sqlSession, user DAO etc…)
- create mapper files which location that you wrote on mapperLocations value
<property name="mapperLocations" value="classpath:/sql/*.xml"/>
- execute your sql with SqlSession. (there are many methods in Sqlsession class)
@Autowired private SqlSession session;
@RequestMapping("/hello") public String hello(Model model, @RequestParam(value="name",required=false)String name){ model.addAttribute("greeting","안녕하세요, "+name);
List<Map<String, Object>> resultMap = session.selectList("AccountMapper.selectAll"); for(Map<String, Object> map : resultMap){ System.out.println(map); } return "hello"; }