package com.dx.test;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javassist.expr.NewArray;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.dx.dao.BaseDao;
import com.dx.model.Course;
import com.dx.model.Produ;
import com.dx.model.Score;
import com.dx.model.Student;
import com.dx.model.Teacher;
import com.dx.model.User;
import com.dx.service.IHelloService;
public class DxTest {
@Test
public void test_010(){
ApplicationContext context = new
ClassPathXmlApplicationContext("context/applicationContext-*.xml");
}
@Test
public void test_020(){
System.out.println();
}
@Test
public void testSave_010(){
IHelloService service = (IHelloService) getBean("hellos");
User user = new User();
user.setName("杨钰莹12");
service.add(user);
System.out.println(new Date().toLocaleString());
}
@Test
public void testGet_010(){
BaseDao baseDao = (BaseDao) getBean("baseDao");
System.out.println(new Date().toLocaleString());
User user = null;
user = baseDao.get(User.class, 1);
System.out.println(user.getName());
User user2 = baseDao.get(User.class, 1);
System.out.println(user2.getName());
System.out.println(new Date().toLocaleString());
}
private Object getBean(String name){
ApplicationContext context = new
ClassPathXmlApplicationContext("context/applicationContext-*.xml");
return context.getBean(name);
}
@Test
public void testUpdate(){
BaseDao baseDao = (BaseDao) getBean("baseDao");
Student student = new Student();
Teacher teacher = new Teacher();
Score score = new Score();
Course course = new Course();
Random random = new Random();
course = baseDao.get(Course.class, 2);
for (int i = 11; i <= 15; i++) {
score = baseDao.get(Score.class, i);
score.setCourse(course);
baseDao.update(score);
}
}
@Test
public void testQuery(){
//查询选择1号课程比2号课程成绩高的学生
/*String sql2 = "select a.id as id,b.score as b_score,a.score as a_score " +
"from (select * from dx_score where course_id=1) as a,(select * from dx_score where course_id=2) as b " +
"where a.score>b.score and a.student_id=b.student_id";*/
//查询选择1号课程的成绩比平均成绩大的学生
String hql = "select a.student_id,a.score,temp.avg_score " +
"from (select avg(score) as avg_score from dx_score where course_id=1) temp,dx_score a " +
"where a.score>temp.avg_score";
String sql2 = "select a.student_id,a.score,sc.avg_score " +
"from (select avg(score) as avg_score from dx_score group by course_id) as sc,score as a" +
"where a..score>sc.avg_score";
//查询平均分大于60的学生号以及平均成绩
String sql3 = "select distinct a.student_id,tm.avg_score " +
"from (select student_id,avg(score) as avg_score from dx_score group by student_id) tm,dx_score a " +
"where tm.avg_score>60 and a.student_id=tm.student_id";
//查询平均分大于60的学生名称以及平均成绩
String sql4 = "select distinct a.name,tm.avg_score " +
"from (select student_id,avg(score) as avg_score from dx_score group by student_id) tm,dx_student a " +
"where tm.avg_score>60 and a.id=tm.student_id";
//查询平均分大于60的学生名称以及平均成绩
String sql5 = "select a.name,tm.avg_score " +
"from (select student_id,avg(score) as avg_score " +
"from dx_score group by student_id " +
"having avg(score)>60) tm,dx_student a " +
"where a.id=tm.student_id";
BaseDao baseDao = (BaseDao) getBean("baseDao");
System.out.println(new Date().toLocaleString());
List<Object[]> list = (List<Object[]>) baseDao.queryBySql(sql5,0,3);
for (Object[] objects : list) {
System.out.println(objects[0]+" "+objects[1]);
}
System.out.println(new Date().toLocaleString());
}
@Test
public void testQueryByHql(){
String hql2 = "from Produ";
BaseDao baseDao = (BaseDao) getBean("baseDao");
System.out.println(new Date().toLocaleString());
List<Produ> list = (List<Produ>) baseDao.query(hql2);
System.out.println(new Date().toLocaleString());
for (Produ score : list) {
System.out.println(score.getName());
}
/*for (Object[] objects : list) {
System.out.println(objects[0]+" "+objects[1]+" "+objects[2]);
}*/
}
@Test
public void testQueryBySql(){
String hql2 = "select id,student_id,course_id,score from dx_score";
String hql3 = "select * from dx_produ";
BaseDao baseDao = (BaseDao) getBean("baseDao");
System.out.println(new Date().toLocaleString());
List<Object[]> list = (List<Object[]>) baseDao.queryBySql(hql3);
System.out.println(new Date().toLocaleString());
/*for (Score score : list) {
System.out.println(score.getScore());
}*/
for (Object[] objects : list) {
System.out.println(objects[0]+" "+objects[1]+" "+objects[2]);
}
}
@Test
public void testProcedureQuery(){
BaseDao baseDao = (BaseDao) getBean("baseDao");
System.out.println(new Date().toLocaleString());
List<Object[]> list = (List<Object[]>) baseDao.queryBySql("{call getProduList()}");
System.out.println(new Date().toLocaleString());
/*for (Score score : list) {
System.out.println(score.getScore());
}*/
for (Object[] objects : list) {
System.out.println(objects[0]+" "+objects[1]+" "+objects[2]);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
本示例用cxf2.6.1+spring3.1.0+hibernate3.6 开发web services . 包括客户端是java project, cxf_010 服务器端是个web程序cxf_web_010. 其中客户端的com.dx.client 包下的代码是通过wsdl2java的命令生成,复制到客户端中程序中去的。 附上我的博客地址http://254633397.iteye.com/blog/1750671 有详细的步骤
资源推荐
资源详情
资源评论
收起资源包目录
cxf 开发web services 利用spring 集成了hibernate (202个子文件)
DxTest.class 6KB
ObjectFactory.class 4KB
BaseDaoImpl.class 4KB
BaseDaoImpl.class 4KB
IHelloServiceTest.class 3KB
IHelloServiceImplService.class 3KB
IHelloServiceImplService.class 3KB
IHelloService_IHelloServiceImplPort_Client.class 2KB
ObjectFactory.class 2KB
IHelloServiceImpl.class 2KB
Score.class 1KB
Score.class 1KB
IHelloService.class 1KB
User.class 1KB
Student.class 1KB
Student.class 1KB
Course.class 1011B
Course.class 1011B
User.class 940B
User.class 940B
Produ.class 917B
Produ.class 917B
GetUserResponse.class 873B
SayHelloResponse.class 873B
SayHelloResponse.class 871B
BaseDao.class 822B
BaseDao.class 822B
IHelloService.class 799B
SayHello.class 767B
SayHello.class 765B
Add.class 751B
Teacher.class 743B
Teacher.class 743B
GetUser.class 710B
AddResponse.class 507B
IHelloService.class 389B
package-info.class 242B
package-info.class 241B
.classpath 3KB
.classpath 1KB
org.eclipse.wst.common.component 560B
org.eclipse.wst.jsdt.ui.superType.container 49B
tab.css 3KB
Thumbs.db 61KB
login_09.gif 22KB
login_04.gif 19KB
login_06.gif 14KB
login_03.gif 5KB
main_08.gif 5KB
left_tree.gif 5KB
login_08.gif 5KB
main_11.gif 4KB
main_12.gif 3KB
login_07.gif 2KB
main_21.gif 2KB
main_31.gif 2KB
main_28.gif 2KB
main_31_1.gif 2KB
main_29_1.gif 2KB
main_26_1.gif 2KB
main_26.gif 2KB
main_06.gif 2KB
main_07.gif 2KB
tab_05.gif 1KB
tab_03.gif 1KB
tab_07.gif 1KB
g_page.gif 1024B
005.gif 1024B
dl.gif 984B
back.gif 749B
next.gif 745B
last.gif 741B
go.gif 736B
first.gif 736B
main_45.gif 726B
main_01.gif 682B
main_09.gif 617B
311.gif 608B
a.gif 556B
main_23.gif 420B
main_16.gif 405B
main_49.gif 400B
083.gif 341B
114.gif 337B
main_51.gif 322B
main_14.gif 309B
main_47.gif 309B
002.gif 308B
tab_14.gif 263B
001.gif 213B
arrow_082.gif 181B
tab_20.gif 164B
main_04.gif 140B
tab_22.gif 131B
037.gif 118B
tab_12.gif 112B
tab_16.gif 112B
a1.gif 100B
main_38.gif 97B
main_40.gif 91B
共 202 条
- 1
- 2
- 3
资源评论
- Zhouxiaolan19882013-10-22不错能用,就是分有点高
- cutecute2014-04-29没有jar包啊
- tonic12016-02-03可用,点个赞
csgvsjay1000
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功