http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
classpath:/jdbc.properties
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
5、mybatis-generator.xml (MyBatis自动生成映射文件:model、dao)
[html] view plaincopy
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
connectionURL="jdbc:mysql://localhost/can_mall" userId="root"
password="123">
targetProject="src/main/java">
targetProject="src/main/resources">
targetPackage="cn.com.abel.springProject.dao" targetProject="src/main/java">
6、IndexController.java
[java] view plaincopypackage cn.com.abel.springProject.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.com.abel.springProject.dao.TestModelMapper;
import cn.com.abel.springProject.model.TestModel;
/**
TestModelMapper与TestModel为Mybatis自动生成的dao和model
*/
@Controller
@RequestMapping("")
public class IndexController {
@Autowired
private TestModelMapper testDao;
@RequestMapping
public String index(ModelMap model) {
//从testTable中查找ID为1的记录
TestModel testModel = testDao.selectByPrimaryKey(1L);
model.addAttribute("testModel", testModel);
model.addAttribute("hello", "hfffello spring mvc");
return "index";
}
}
原文转自:http://blog.csdn.net/rongku/article/details/13053455