sql查询参数 传值到 连接查询

新增一个字段,做跳板,把参数传递给连接查询 {openId} as currentId


// resultMap
<resultMap id="appDeliberativeMeetingProgressOpenIdMap" type="com.sinoecare.vc2.common.core.bean.AppDeliberativeMeetingProgress">
		<id property="id" column="id"/>
		<result property="meetingId" column="meeting_id"/>
		<result property="type" column="type"/>
		<result property="progressId" column="progress_id"/>
		<result property="name" column="name"/>
		<result property="areaName" column="area_name"/>
		<result property="content" column="content"/>
		<result property="commentVoice" column="comment_voice"/>
		<result property="supportedQuantity" column="supported_quantity"/>
		<result property="objectionQuantity" column="objection_quantity"/>
		<result property="hotCount" column="hot_count"/>
		<result property="commentTime" column="comment_time"/>
		<result property="openId" column="open_id"/>
		<collection property="secondProgressList" column="{id=id,currentId = currentId}" ofType="com.sinoecare.vc2.common.core.bean.AppDeliberativeMeetingProgress"
					select="querySecondProgressOpenIdList" javaType="java.util.List">
		</collection>
	</resultMap>
// 主查询
SELECT
		t1.id,
		t1.meeting_id,
		t1.type,
		t1.progress_id,
		t1.name,
		t1.area_name,
		t1.content,
		t1.comment_voice,
		t1.supported_quantity,
		t1.objection_quantity,
		t1.hot_count,
		t1.comment_time,
		t1.open_id,
		#{openId} as currentId,
		(select tt.status from app_deliberative_meeting_progress_hot tt where tt.progress_id = t1.id and tt.open_id =#{openId}) as status
		FROM app_deliberative_meeting_progress t1
		where (ISNULL(t1.progress_id) || LENGTH(trim(t1.progress_id)) &lt; 1)
SELECT
		t1.id,
		t1.meeting_id,
		t1.type,
		t1.progress_id,
		t1.name,
		t1.area_name,
		t1.content,
		t1.comment_voice,
		t1.supported_quantity,
		t1.objection_quantity,
		t1.hot_count,
		t1.comment_time,
		t1.open_id,
		(select tt.status from app_deliberative_meeting_progress_hot tt where tt.progress_id = t1.id and tt.open_id =#{currentId}) as status
		FROM app_deliberative_meeting_progress t1
		where t1.progress_id = #{id}
		order by t1.hot_count desc,t1.comment_time asc
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
首先,你需要在数据库中创建一个用户表来存储用户信息,例如用户名、密码和其他相关信息。然后,你需要编写一个登陆窗口和主窗口的代码。 在登陆窗口中,你需要编写代码来验证用户输入的用户名和密码是否正确。如果正确,你可以将用户的信息存储在一个变量中,并在主窗口中使用这些信息。 在主窗口中,你可以根据用户的信息从数据库中检索相关的数据,并在窗口中显示这些数据。以下是一个简单的示例代码: ``` // 登陆窗口代码 private void btnLogin_Click(object sender, EventArgs e) { string username = txtUsername.Text; string password = txtPassword.Text; // 连接数据库并查询用户信息 string connectionString = "Data Source=YOUR_DATABASE_SERVER;Initial Catalog=YOUR_DATABASE_NAME;Integrated Security=True"; string query = "SELECT * FROM Users WHERE Username='" + username + "' AND Password='" + password + "'"; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); // 如果用户存在,则保存用户信息并打开主窗口 if (reader.HasRows) { reader.Read(); int userId = reader.GetInt32(0); string userFullName = reader.GetString(1); // 保存用户信息到变量中 User currentUser = new User(userId, username, userFullName); // 打开主窗口,并传递用户信息 MainForm mainForm = new MainForm(currentUser); mainForm.Show(); this.Hide(); } else { MessageBox.Show("Invalid username or password"); } reader.Close(); connection.Close(); } // 主窗口代码 public partial class MainForm : Form { private User currentUser; public MainForm(User user) { InitializeComponent(); // 保存当前用户信息 currentUser = user; // 根据用户信息从数据库中检索相关数据 string connectionString = "Data Source=YOUR_DATABASE_SERVER;Initial Catalog=YOUR_DATABASE_NAME;Integrated Security=True"; string query = "SELECT * FROM UserData WHERE UserId=" + currentUser.Id; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); // 在窗口中显示相关数据 if (reader.HasRows) { reader.Read(); string userData = reader.GetString(1); txtData.Text = userData; } reader.Close(); connection.Close(); } } // 用户类 public class User { public int Id { get; set; } public string Username { get; set; } public string FullName { get; set; } public User(int id, string username, string fullName) { Id = id; Username = username; FullName = fullName; } } ``` 在这个示例代码中,我们假设用户表中有两个列:Id、Username、Password和FullName。我们还假设UserData表中有两个列:UserId和Data。 在登陆窗口中,我们首先获取用户输入的用户名和密码,并使用这些信息查询用户表。如果用户存在,则我们将其信息存储在一个User对象中,并打开主窗口。否则,我们显示一个错误消息。 在主窗口中,我们首先在构造函数中保存当前用户信息。然后,我们使用这些信息从数据库中检索UserData表中的相关数据,并在窗口中显示它。 请注意,这只是一个简单的示例代码,你需要根据你的特定需求进行修改。还要注意安全性问题,例如使用参数查询来防止SQL注入攻击。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值