package com.yihaomen.test;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.yihaomen.mybatis.inter.UserMapper;
import com.yihaomen.mybatis.model.Article;
import com.yihaomen.mybatis.model.User;
@Service("mybatisSprintTest")
public class MybatisSprintTest{
@Autowired
private UserMapper mapper;
@Transactional(propagation = Propagation.REQUIRED)
public void insert() {
// 测试id=1的用户查询,根据数据库中的情况,可以改成你自己的.
System.out.println("得到用户id=1的用户信息");
System.out.println(mapper);
User user = mapper.selectUserByID(1);
System.out.println(user.getUserAddress());
// 得到文章列表测试
System.out.println("得到用户id为1的所有文章列表");
List<Article> articles = mapper.getUserArticles(1);
for (Article article : articles) {
System.out.println(article.getContent() + "--" + article.getTitle());
}
User newUser = new User();
newUser.setUserAddress("a");
newUser.setUserAge(5);
newUser.setUserName("zhangyang");
// 插入用户
mapper.addUser(newUser);
// 插入后返回自增长ID
System.out.println(newUser.getId()+"insert success");
// 插入用户
mapper.addUser(newUser);
// 插入后返回自增长ID
System.out.println(newUser.getId()+"insert success");
// 抛出异常,@Transactional做事务回滚(两条数据都不会插入)
throwException();
}
private static void throwException() {
throw new RuntimeException();
}
public UserMapper getMapper() {
return mapper;
}
public void setMapper(UserMapper mapper) {
this.mapper = mapper;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论










格式:rar 资源大小:29.3MB

















收起资源包目录





































































































共 100 条
- 1

Simple_Coffee
- 粉丝: 7
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 医院网络与信息安全应急预案.doc
- 2005年9月全国计算机等级考试三级网络技术笔试真题88498.doc
- 互联网+时代高等学校混合式教学创新探索.docx
- 优必选曼城战略合作发布会互联网IT计算机专业资料.ppt
- 工程量算法技术文件.doc
- 基于改进MPPT算法的光伏发电系统设计.docx
- 浅析变电站电力系统自动化智能控制技术.docx
- 基于Web的远程温湿度监测系统的方案设计书(2).doc
- 某医院计算机网络综合布线系统设计.docx
- 网络化行车组织需求.docx
- 地铁列车运行仿真算法研究.docx
- 小型企业网络工程方案设计书实施方案书.doc
- 谈服务器虚拟化技术在主机运维中的运用.docx
- 对职业高中计算机基础教学实践探索.docx
- 新形势下机械设计制造及其自动化发展微探.docx
- Python-Python资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

- 1
- 2
- 3
前往页