package action.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import action.entity.Student;
import action.service.StudentService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
//用ModelAndView转到login.html(登录界面)
@RequestMapping("toLogin")
public ModelAndView toLogin() {
ModelAndView mv=new ModelAndView();
mv.setViewName("login");
return mv;
}
//登录方法
@RequestMapping("login")
@ResponseBody
public JSONObject login(@RequestParam(defaultValue="username",required=false)String username,
@RequestParam(defaultValue="password",required=false)String password,
HttpServletRequest request){
Student student=studentService.checkLogin(username, password);
//if(student!=null){
JSONObject student_json = JSONObject.fromObject(student);
System.out.println("student_json="+student_json);
return student_json;
//}
//return null;
}
//显示所有数据
@RequestMapping("list")
@ResponseBody
public JSONArray list(){
List<Student> list=studentService.findAll();
JSONArray json=JSONArray.fromObject(list);
return json;
}
//修改数据
@RequestMapping("update")
@ResponseBody
public String update(@RequestParam Map<Object,Object> map){
//Object转Integer类型
Integer id = Integer.parseInt(map.get("id").toString());
System.out.println("id="+id);
Student student=studentService.findById(id);
String name=String.valueOf(map.get("name"));
String username=String.valueOf(map.get("username"));
String password=String.valueOf(map.get("password"));
String sex=String.valueOf(map.get("sex"));
String classname=String.valueOf(map.get("classname"));
Integer chinese=Integer.parseInt(map.get("chinese").toString());
Integer english=Integer.parseInt(map.get("english").toString());
Integer math=Integer.parseInt(map.get("math").toString());
//给student赋值
student.setName(name);
student.setUsername(username);
student.setPassword(password);
student.setSex(sex);
student.setClassname(classname);
student.setChinese(chinese);
student.setEnglish(english);
student.setMath(math);
int num=studentService.updateById(student);
return String.valueOf(num);
}
//添加数据
@RequestMapping("saveStudent")
@ResponseBody
public String saveStudent(@RequestParam Map<Object,Object> map){
//用map接收值
String name=String.valueOf(map.get("name"));
String username=String.valueOf(map.get("username"));
String password=String.valueOf(map.get("password"));
String sex=String.valueOf(map.get("sex"));
String classname=String.valueOf(map.get("classname"));
Integer chinese=Integer.parseInt(map.get("chinese").toString());
Integer english=Integer.parseInt(map.get("english").toString());
Integer math=Integer.parseInt(map.get("math").toString());
//给student赋值
Student student=new Student();
student.setName(name);
student.setUsername(username);
student.setPassword(password);
student.setSex(sex);
student.setClassname(classname);
student.setChinese(chinese);
student.setEnglish(english);
student.setMath(math);
int num=studentService.saveStudent(student);
return String.valueOf(num);
}
//删除数据
@RequestMapping("deleteStudent")
@ResponseBody
public String deleteStudent(@RequestParam(defaultValue="id",required=false)Integer id){
int num=studentService.deleteStudent(id);
return String.valueOf(num);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
html+ajax+ssm写的增删改查
共62个文件
xml:10个
java:9个
class:9个
需积分: 50 37 下载量 115 浏览量
2018-04-02
23:17:58
上传
评论 2
收藏 1.86MB ZIP 举报
温馨提示
通过父子页面来实现:增删改查,子页面通过文本框,来获取父页面的数据,不过网页特别的简陋。
资源推荐
资源详情
资源评论
收起资源包目录
SSM1.zip (62个子文件)
SSM1
.project 1KB
src
test
resources
java
main
webapp
WEB-INF
lib
commons-beanutils-1.8.3.jar 227KB
ezmorph-1.0.6.jar 84KB
commons-logging-1.1.1.jar 59KB
commons-io-2.0.1.jar 156KB
json-lib-2.4-jdk15.jar 155KB
commons-fileupload-1.2.1.jar 56KB
commons-lang-2.6.jar 278KB
commons-collections-3.2.1.jar 562KB
web.xml 1KB
views
js
jgcharts.js 24KB
echarts.min.js 632KB
echarts.simple.min.js 240KB
jquery-2.1.1.js 82KB
jquery-1.3.1.min.js 54KB
jquery-3.2.1.min.js 85KB
html
index.html 115KB
save.html 2KB
login.html 1KB
update.html 3KB
resources
spring-mybatis.xml 3KB
spring-mvc.xml 2KB
jdbc.properties 294B
log4j.properties 925B
java
action
service
StudentService.java 403B
impl
StudentServiceImpl.java 1KB
mapper
Student.xml 2KB
dao
StudentDAO.java 749B
Test.java 205B
web
ForwardAction.java 909B
StudentController.java 4KB
util
JsonUtil1.java 586B
JsonUtil.java 385B
entity
Student.java 2KB
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 114B
maven
SM
SM
pom.properties 206B
pom.xml 6KB
classes
action
service
impl
StudentServiceImpl.class 2KB
StudentService.class 501B
mapper
Student.xml 2KB
dao
StudentDAO.class 639B
Test.class 601B
web
StudentController.class 5KB
ForwardAction.class 1KB
util
JsonUtil.class 1KB
JsonUtil1.class 1KB
entity
Student.class 3KB
spring-mybatis.xml 3KB
spring-mvc.xml 2KB
jdbc.properties 294B
log4j.properties 925B
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 430B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 162B
org.eclipse.wst.common.component 653B
.jsdtscope 639B
pom.xml 6KB
.classpath 2KB
共 62 条
- 1
资源评论
wang18855148001
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功