?
本文 由于上一篇?mybatis+mysql+springmvc + multidatasource+mchange 没有跑通 换另一种 不是aop 注入写的文章 看过这一篇博客的,可以看看上一篇 ,帮我找到错误。。。。。?
?
?
自动生成 代码 (自动生成mysql+springmvc + mybatis )?
http://knight-black-bob.iteye.com/blog/2208162
?http://download.csdn.net/download/knight_black_bob/9226373
?
mybatis+mysql+springmvc + multidatasource+Atomikos 多数据源?
下载 :http://download.csdn.net/download/knight_black_bob/9233289
?
?
jar ?包括
Atomikos的:?
transactions-jdbc?
transactions-jta?
transactions-api?
transactions?
atomikos-utils?
?
使用 maven
?
?
?
?
application Context .xml
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:cOntext="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
?
applicationContext-mybatis.xml
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:cOntext="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
?
springmvc-servlet.xml
xmlns:p="http://www.springframework.org/schema/p" xmlns:cOntext="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
p:prefix="" p:suffix=".jsp">
?
web.xml
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
?
UserDao
package cn.com.oneweb.dao; ? Mapper.xml ? service? package cn.com.oneweb.service; ? ? controller import java.util.List; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
import java.util.List;
import cn.com.baoy.bean.User;
public interface UserDao {
//查所有
public List
//删除
public void delUser(int userId);
//获取一个form
public User user(int userId);
//修改
public void updateUser(User user);
//添加
public void addUser(User user);
}
delete from t_user where userId = #{ userId}
INSERT INTO t_user
(userId,userName,password,tel,sex,description)
VALUE (null,#{userName},#{password},#{tel},#{sex},#{description})
update t_user
where userId = #{ userId}
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.com.baoy.bean.User;
import cn.com.oneweb.dao.UserDao;
@Service
public class UserService {
@Autowired
UserDao userDao;
public List
return userDao.allUser();
}
public void delUser(int userId){
userDao.delUser(userId);
}
public User user(int userId){
return userDao.user(userId);
}
public void updateUser(User user){
userDao.updateUser(user);
}
public void addUser(User user){
userDao.addUser(user);
}
}
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import cn.com.baoy.bean.User;
import cn.com.oneweb.service.UserService;
import cn.com.twoweb.service.User2Service;
@Controller
public class UserController {
@Autowired
User2Service user2Service;
@Autowired
UserService userService;
@RequestMapping(value = "/userView.do")
public String userView(ModelMap modelMap,String pageNo, String choice, HttpSession session){
List
List
userList.addAll(userList2);
modelMap.put("userList", userList);
return "back/jsp/user/userView";
}