java源代码是给你一个身份证号,通过面板身份证号的输入,显示出该身份证主人的出生年月,省份,性别等资料
发布网友
发布时间:2022-04-23 22:41
我来回答
共1个回答
热心网友
时间:2023-10-12 12:56
我当初用struts1和hibernate做了个简单的!主要的逻辑代码在下面!数据库里号码对应的城市在网上可以查的到
package ;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Expression;
import entity.Shenfenzhen;
public class IdDao {
private static Configuration configuration = new Configuration().configure() ;
private static SessionFactory sessionFactory =configuration.buildSessionFactory();
private static Session session = null;
public Info query(String s){
Info info = null;
StringBuffer stringBuffer = new StringBuffer(s);
if(s.length()==18){
String end = stringBuffer.substring(17);
//System.out.println(end);
if(!end.matches("\\d||x")){
return null;
}
}
else if(s.length()==15){
stringBuffer.insert(6, "19");
stringBuffer.append("3");
}
int i = Integer.parseInt(stringBuffer.substring(0, 6));
//System.out.println(i);
session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(Shenfenzhen.class);
criteria.add(Expression.eq("num", i));
List<Shenfenzhen> list = criteria.list();
String address = null;
try {
address = list.get(0).getAddress();
}catch (Exception e) {
return null;
}
i = Integer.parseInt(stringBuffer.substring(16,17));
String sex = null;
if(i%2==0){
sex = "女";
}else{
sex = "男";
}
//System.out.println(i);
stringBuffer = new StringBuffer(stringBuffer.substring(6, 14));
//stringBuffer.insert(4, "-");
//stringBuffer.insert(7, "-");
//System.out.println(stringBuffer);
String ss = stringBuffer.toString();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String brithday="";
int year=0;
int month =0;
int day =0;
try {
Date date = dateFormat.parse(ss);
//System.out.println(date);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH)+1;
day = calendar.get(Calendar.DAY_OF_MONTH);
brithday = (String)(year + "年" + month + "月" + day + "日");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
info = new Info(address, brithday, sex);
Calendar c = Calendar.getInstance();
int nowYear = c.get(Calendar.YEAR);
int nowMonth = c.get(Calendar.MONTH);
int nowDay = c.get(Calendar.DAY_OF_MONTH);
if(nowYear<year){
info = null;
}else if(nowYear ==year && nowMonth<month ){
info = null;
}else if(nowYear == year && nowMonth==month && nowDay<day){
info = null;
}
closeSession(session);
return info;
}
//public static void main(String[] args){
//IdDao = new IdDao();
//.query("342522998711224513");
//System.out.println("x".matches("\\d||x"));
//}
private void closeSession(Session session){
if(session !=null){
session.close();
}
}
}