package net.csdn.blog.chaijunkun.controller;
import net.csdn.blog.chaijunkun.entity.Resp;
import net.csdn.blog.chaijunkun.entity.Teacher;
import net.csdn.blog.chaijunkun.service.TeacherService;
import net.csdn.blog.chaijunkun.validation.group.TeacherGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* 学生控制器
* @author chaijunkun
* @since 2015年4月3日
*/
@Controller
@RequestMapping(value = "teacher")
public class TeacherController {
@Autowired
private TeacherService teacherService;
@ResponseBody
@RequestMapping(value = "add", method = {RequestMethod.POST})
public Resp<?> add(@Validated(TeacherGroup.Add.class) Teacher teacher, BindingResult result){
Integer id = teacherService.add(teacher);
if (id == null){
return Resp.fail("添加学生信息失败");
}else{
return Resp.success(id);
}
}
@ResponseBody
@RequestMapping(value = "del", method = {RequestMethod.GET})
public Resp<?> del(@Validated(TeacherGroup.Del.class) Teacher teacher, BindingResult result){
if (teacherService.del(teacher.getId())){
return Resp.success(true);
}else{
return Resp.fail("删除学生信息失败");
}
}
@ResponseBody
@RequestMapping(value = "get", method = {RequestMethod.GET})
public Resp<?> get(@Validated(TeacherGroup.Get.class) Teacher teacher, BindingResult result){
Teacher data = teacherService.get(teacher.getId());
if (data == null){
return Resp.fail("未找到指定学生");
}else{
return Resp.success(data);
}
}
@ResponseBody
@RequestMapping(value = "update", method = {RequestMethod.POST})
public Resp<?> update(@Validated(TeacherGroup.Update.class) Teacher teacher, BindingResult result){
if (teacherService.update(teacher)){
return Resp.success(true);
}else{
return Resp.fail("更新学生信息失败");
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
如今互联网项目都采用HTTP接口形式进行开发。无论是Web调用还是智能设备APP调用,只要约定好参数形式和规则就能够协同开发。返回值用得最多的就是JSON形式。服务端除了保证正常的业务功能,还要经常对传进来的参数进行验证,例如某些参数不能为空,字符串必须含有可见字符,数值必须大于0等这样的要求。那么如何做到最佳实践,让接口开发的效率提升呢?今天我们就来聊一聊JSR 303和AOP的结合。详细文章请参阅:http://blog.csdn.net/chaijunkun/article/details/44854071
资源推荐
资源详情
资源评论
收起资源包目录
jsraop.zip (16个子文件)
jsraop
pom.xml 3KB
src
test
resources
java
main
webapp
WEB-INF
web.xml 2KB
index.jsp 52B
resources
log4j.properties 270B
dispatcher-servlet.xml 2KB
spring-config.xml 634B
java
net
csdn
blog
chaijunkun
aop
JSRValidationAdvice.java 2KB
validation
group
StudentGroup.java 300B
TeacherGroup.java 300B
controller
StudentController.java 2KB
TeacherController.java 2KB
service
TeacherService.java 932B
StudentService.java 932B
entity
Teacher.java 1KB
Student.java 1KB
Resp.java 934B
共 16 条
- 1
资源评论
- yulingjie20062016-04-13研究学习学习
- wyfx092017-08-29不错,学习了
- Alanzhou0072016-01-28时候初学者看看。
- cheng435268992015-06-08下载来研究学习学习,博客里面介绍的还不错。
- binibaichi2222018-08-03呵呵,一般吧,我是不需要的
Jack_Chai
- 粉丝: 564
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功