知道美河 | 上传资料 | VIP申请 | 精品课程 | 资料搜索 | 问题反馈 | 会员手册 | 积分消费 | 积分充值 | 帐号保护
美河学习学习在线赞助VIP

美河学习在线(主站) eimhe.com

 找回密码
 建立账号
查看: 6830|回复: 1

[求助] 我的查询怎么不对的 啊

[复制链接]
发表于 2008-3-22 11:28:47 | 显示全部楼层 |阅读模式
public List getpossiblehistory(String name, String sex, String phone, String politics, String school, String major, String education, String jobType, String province, String city, String county, String state, String personType) {
        String sql = "from HpersonMsg ";
               
                sex = sex.trim();
                politics = politics.trim();
                education = education.trim();
                province = province.trim();
                city = city.trim();
                county = county.trim();
                personType = personType.trim();
                state = state.trim();
               
                if (name!= null || sex != null || phone != null || politics != null || school != null || education != null || major != null || jobType != null || province != null || city != null || county != null || state != null || personType != null )
                {
                        sql += " where ";
                        int n = 0;//控制
                        if (name != null) {
                                sql += "name like'%" + name + "%'";
                                n++;
                        }
                        if (sex != null) {
                                if (n == 0) {
                                        sql += "sex like'%" + sex + "%'";
                                        n++;
                                } else {
                                        sql += " and sex like'%" + sex + "%'";
                                        n++;
                                }
                        }
                        if (phone != null) {
                                if (n == 0) {
                                        sql += "phone like'%" + phone + "%'";
                                        n++;
                                } else {
                                        sql += " and phone like'%" + phone + "%'";
                                        n++;
                                }
                        }
                        if (politics != null) {
                                if (n == 0) {
                                        sql += "politics like'%" + politics + "%'";
                                        n++;
                                } else {
                                        sql += " and politics like'%" + politics + "%'";
                                        n++;
                                }
                        }
                        if (school != null) {
                                if (n == 0) {
                                        sql += "school like'%" + school + "%'";
                                        n++;
                                } else {
                                        sql += " and school like'%" + school + "%'";
                                        n++;
                                }
                        }
                        if (education != null) {
                                if (n == 0) {
                                        sql += "education like '%" + education + "%'";
                                        n++;
                                } else {
                                        sql += " and education like '%" + education + "%'";
                                        n++;
                                }
                        }
                        if (major != null) {
                                if (n == 0) {
                                        sql += "major like '%" + major + "%'";
                                        n++;
                                } else {
                                        sql += " and major like '%" + major + "%'";
                                        n++;
                                }
                        }
                       
                        if (jobType != null) {
                                if (n == 0) {
                                        sql += "jobType like '%" + jobType + "%'";
                                        n++;
                                } else {
                                        sql += " and jobType like '%" + jobType + "%'";
                                        n++;
                                }
                        }
                        if (province != null) {
                                if (n == 0) {
                                        sql += "province like '%" + province + "%'";
                                        n++;
                                } else {
                                        sql += " and province like '%" + province + "%'";
                                        n++;
                                }
                        }
                        if (city != null) {
                                if (n == 0) {
                                        sql += "city like '%" + city + "%'";
                                        n++;
                                } else {
                                        sql += " and city like '%" + city + "%'";
                                        n++;
                                }
                        }
                        if (county != null) {
                                if (n == 0) {
                                        sql += "county like '%" + county + "%'";
                                        n++;
                                } else {
                                        sql += " and county like '%" + county + "%'";
                                        n++;
                                }
                        }
                       
                       
                        if (state != null) {
                                if (n == 0) {
                                        sql += "state like'%" + state + "%'";
                                        n++;
                                } else {
                                        sql += " and state like'%" + state + "%'";
                                        n++;
                                }
                        }
                        if (personType != null) {
                                if (n == 0) {
                                        sql += "personType like'%" + personType + "%'";
                                        n++;
                                } else {
                                        sql += " and personType like'%" + personType + "%'";
                                        n++;
                                }
                        }
                       
                }
                return getHibernateTemplate().find(sql);
        }
 楼主| 发表于 2008-3-22 11:32:56 | 显示全部楼层
,没人啊   出来查询的结果不对啊

上面的 这些属性是从表单获取的啊
您需要登录后才可以回帖 登录 | 建立账号

本版积分规则

 
QQ在线咨询

QQ|小黑屋|手机版|Archiver|美河学习在线 ( 浙网备33020302000026号 )

GMT+8, 2025-5-3 17:53

Powered by Discuz!

© 2001-2025 eimhe.com.

快速回复 返回顶部 返回列表