自己编写阿里云settings.xml

本文介绍了一个基于Java的消息管理系统,包括消息的增删查改、分页查询及回复功能。使用了Apache Commons DbUtils库进行数据库操作,实现了根据学生ID查找消息总数、按页获取消息列表、添加新消息、查找所有消息总数、按页获取教师视图下的消息列表、回复消息及通过ID查找特定消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打开一个空记事本,复制粘贴下列代码:

package cn.lk.wjyl.dao;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import cn.lk.wjyl.domain.Message;
import cn.lk.wjyl.domain.Student;
import cn.lk.wjyl.utils.JDBCUtils;

public class MessageDao {

	public int findTotalRecordsByStuId(Student stu) throws SQLException {
		String sql="select count(*) from t_message where stuId=?";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		Number num=(Number)qr.query(sql, new ScalarHandler(),stu.getStuId());
		return num.intValue();
	}

	public List<Message> findMessagesWithPage(int startIndex, Student stu) throws SQLException {
		String sql="select top 5 * from t_message where stuId = ? and  messageId not in (select top (?) messageId from t_message where stuId = ? order by leaveWordTime desc) order by leaveWordTime desc";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		return qr.query(sql, new BeanListHandler<Message>(Message.class),stu.getStuId(),startIndex,stu.getStuId());
	}

	public void addMessage(Message msg) throws SQLException {
		String sql="insert into t_message (content,leaveWordTime,stuId) values ( ? , ? , ? )";
		Object[] params= {msg.getContent(),msg.getLeaveWordTime(),msg.getStuId()};
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		qr.update(sql,params);
	}

	public int findTotalRecords() throws SQLException {
		String sql="select count(*) from t_message";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		Number num=(Number)qr.query(sql, new ScalarHandler());
		return num.intValue();
	}

	public List<Message> findMessagesWithPageByTeacher(int startIndex) throws SQLException {
		String sql="select top 5 * from t_message where messageId not in (select top (?) messageId from t_message order by leaveWordTime desc) order by leaveWordTime desc";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		return qr.query(sql, new BeanListHandler<Message>(Message.class),startIndex);
	}

	public void replayMessage(String id, String replay) throws SQLException {
		String sql="update t_message set replay =? , replayTime = ? where messageId=?";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		String replayTime=sdf.format(new Date());
		Object[] params= {replay,replayTime,id};
		qr.update(sql,params);
	}
	
	public Message findMessageById(int id) throws SQLException {
		String sql="select * from t_message where messageId = ?";
		QueryRunner qr=new QueryRunner(JDBCUtils.getDataSource());
		return qr.query(sql, new BeanHandler<Message>(Message.class),id);
	}
}

然后保存,命名为settings.xml

打开sts或者eclipse  → 顶部的windows →Preferences ↓ 找到之前编写的settings.xml所保存的路径

注意:setting.xml不能删除,所以尽量不要存放在桌面。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值