0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

关于Date的写法

Last updated at Posted at 2019-06-22

date写法

  • 建表格时

表格中依然是date形式

  • 实体类时
    bean中的实体类,写成String
  • dao层方法实现中
dao.java
//是利用dao层方法,操作数据库的。要往数据库里放数据,是需要转换城数据库要的Date形式
//添加
	@Override
	public boolean addStu(Student stu) {
		String sql = "insert into student values (null,?,?,?,?,?,?,?,?,?,?,?)";
		
               //日期的数据转换! 
		SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
		
		Date date=null;
		try {
           
  //此时这种形式是可以往数据库里放的形式! String 形式-->sql的date!
			date = new Date(sd.parse(stu.getSmtime()).getTime());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
		Object[] obj = {
				
				stu.getSid(),
				stu.getSpwd(),
				stu.getSname(),
				stu.getSgender(),
				stu.getSage(),
				stu.getStel(),
				stu.getSaddress(),
				stu.getSclass(),
				stu.getSenterprise(),
				date,
				stu.getSstatus()		
		};
		return DBUtils.common(sql, obj);
	}
  • 页面中
student.html

//注意: type写成date 就可以出选日期的小插件儿! 
<tr>
	    			<td>入学时间:</td>
	    			<td><input id="edit_smtime" type= "date"  style="width: 200px; height: 30px;" class="easyui-textbox" name="edit_smtime" /></td>
	    		</tr>


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?