前端使用angularjs的$resource发送
这是方法:
@RequestMapping(value = "/studentTest")
public class StudentController {
/**
* 测试
*/
@RequestMapping(value = "/save",method = RequestMethod.POST,consumes = "application/json")
@ResponseBody
public HashMap<String,Object> save(@RequestBody Student student){
HashMap<String,Object> hashMap = new HashMap<String,Object>();
ApplicationContext ctx = new ClassPathXmlApplicationContext("springmvc.xml");
StudentDao studentDao = (StudentDao)ctx.getBean("StudentBean");
if(studentDao.save(student)){
hashMap.put("error", 0);
hashMap.put("msg", "插入测试成功");
}else{
hashMap.put("error", 1);
hashMap.put("msg", "插入测试失败");
}
return hashMap;
}
}
这是前端angularjs的$resource
TestApp.factory('TestService',function($resource){
return $resource(projectName + '/student/courseList',{},{
insert: {
url: projectName + '/studentTest/save',
method: 'POST',
isArray: false,
}
});
});
$scope.registerInfo = [{
'snumber': 'qubxxk',
'sname': "接口测试",
'sage': 10
}]
TestService.insert($scope.registerInfo,function(res){
if(res.error === 0){
if(res.msg !== null){
console.log(res.msg);
}else{
console.log("插入测试成功");
}
}else{
if(res.msg !== null){
console.log(res.msg);
}else{
console.log("插入测试失败");
}
}
console.log(res);
//恢复按钮状态
$scope.test_btn = '插入测试';
$scope.insert_disabled = false;
},function(){
console.log("api连接失败");
$scope.test_btn = '插入测试';
$scope.insert_disabled = false;
});
下面是配置文件springmvc.xml
``
`
另一个配置文件
${driverClassName}
${url}
${username}
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="current_session_context_class">thread</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/bean/Student.hbm.xml</value>
</list>
</property>
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
没用maven就直接下载这个jar包导入就可以了啊
http://blog.csdn.net/tiantiandjava/article/details/46125141
下载地址,http://download.csdn.net/detail/u014259620/8693825
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。