package com.lizc.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.lizc.dao.StudentEvent;
import com.lizc.dao.StudentQuery;
import com.lizc.entity.StudentEntity;
import com.lizc.exception.UpdateStudentException;
import com.lizc.param.ParamResponse;
import com.lizc.param.resp.StudentResp;
import com.lizc.utils.StringUtils;
/**
* 学生业务处理
* @author think
*
*/
@Service
public class StudentService {
@Autowired
private StudentQuery stuQuery;
@Autowired
private StudentEvent stuEvent;
/**
* 获取学生
* @return
*/
public List<StudentEntity> queryAllStudent(){
return stuQuery.queryAllStudentToObject();
}
/**
* 保存学生
* @param student
* @return
* @throws UpdateStudentException 更新学生信息失败异常
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public ParamResponse saveStudent(StudentEntity student) {
StudentResp studentResp = new StudentResp();
try {
/* 添加学生 */
stuEvent.saveStudent(student);
/* 将该学生信息返回给页面 */
studentResp.setRealName(student.getRealName());
studentResp.setUserName(student.getUserName());
studentResp.setSex(student.getSex());
studentResp.setPassWord(student.getPassWord());
studentResp.setClassId(student.getClassId());
studentResp.setDesc(student.getDesc());
/* 添加成功的返回码 */
studentResp.setResultCode("200");
studentResp.setResultMsg("添加成功");
} catch (UpdateStudentException e) {
e.printStackTrace();
studentResp.setResultCode("500");
studentResp.setResultMsg("添加失败");
} catch (Exception e) {
e.printStackTrace();
studentResp.setResultCode("500");
studentResp.setResultMsg("服务异常");
}
return studentResp;
}
/**
* 删除学生
* @param userNameStr
*/
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public void removeStudent(String removeStr){
try {
String userNameStr = StringUtils.splitStrByLine(removeStr, null);
if(userNameStr != null && !"".equals(userNameStr)){
stuEvent.removeStudent(userNameStr);
}
System.out.println(userNameStr);
} catch (UpdateStudentException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
public static void main (String args[]){
try {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
StudentService stuService = (StudentService)context.getBean("studentService");
// StudentEntity stu = new StudentEntity();
// stu.setRealName("西方求败");
// stu.setUserName("xifangqiubai");
// stu.setPassWord("xifangqiubai");
// stu.setSex("女");
// stu.setDesc("邋遢大王");
// stu.setClassId(2);
//
// stuService.saveStudent(stu);
stuService.queryAllStudent();
// System.out.println("sssssss");
} catch (Exception e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
spring.zip (58个子文件)
spring
.project 2KB
.settings
.jsdtscope 500B
org.eclipse.wst.common.component 456B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 291B
WebRoot
WEB-INF
web.xml 851B
spring-form.tld 69KB
spring.tld 17KB
lib
gson-2.1.jar 176KB
mysql-connector-java-5.1.9.jar 707KB
commons-collections-3.2.1.jar 562KB
classes
com
lizc
utils
StringUtils.class 1KB
DateUtils.class 3KB
dao
StudentQuery$1.class 2KB
StudentEvent.class 2KB
StudentQuery.class 3KB
BasicDao.class 641B
action
StudentAction.class 4KB
exception
UpdateStudentException.class 459B
param
StudentParam.class 1KB
ParamResponse.class 966B
resp
StudentResp.class 2KB
aop
StudentAspect.class 2KB
trigger
BatchExportJob.class 2KB
service
StudentService.class 3KB
entity
ClassEntity.class 1KB
StudentEntity.class 2KB
BasicEntity.class 382B
jdbc.properties 254B
applicationContext.xml 4KB
index.jsp 1KB
student.jsp 4KB
META-INF
MANIFEST.MF 36B
tool
jquery
jquery-1.9.1.min.js 90KB
js
student.js 2KB
.myeclipse
src
com
lizc
utils
StringUtils.java 983B
DateUtils.java 3KB
dao
BasicDao.java 430B
StudentEvent.java 1KB
StudentQuery.java 3KB
action
StudentAction.java 3KB
exception
UpdateStudentException.java 332B
param
StudentParam.java 1KB
ParamResponse.java 592B
resp
StudentResp.java 1KB
aop
StudentAspect.java 2KB
trigger
BatchExportJob.java 1KB
service
StudentService.java 3KB
entity
ClassEntity.java 670B
BasicEntity.java 195B
StudentEntity.java 1KB
jdbc.properties 254B
applicationContext.xml 4KB
.springBeans 462B
.classpath 1KB
共 58 条
- 1
资源评论
土逼南波湾007
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C语言基础-C语言编程基础之Leetcode编程题解之第39题组合总和.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第38题外观数列.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第37题解数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第36题有效的数独.zip
- C语言基础-C语言编程基础之Leetcode编程题解之第35题搜索插入位置.zip
- index.wxml
- C语言基础-C语言编程基础之Leetcode编程题解之第33题搜索旋转排序数组.zip
- 基于Python实现的手写数字识别系统源码.zip
- 从网页提取禁止转载的文字
- C语言基础-C语言编程基础之Leetcode编程题解之第32题最长有效括号.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功