mysql 存储过程 睡眠_如何使用休眠在Spring Boot中调用MySQL存储过程?

我已经在 MySQL存储过程 e中编写了一些逻辑。我正在将 spring boot与hibernate一起使用 。我有一个使用 IN

OUT 参数的登录过程。从我的登录过程中,我想将消息传递给用户。但是我不知道如何在Spring Boot中调用存储过程。我的代码在下面。

我的登录过程是

CREATE PROCEDURE login(IN in_user_id varchar(100),

IN in_password varchar(100),

OUT out_code INT,

OUT out_message varchar(100))

BEGIN

IF in_user_id IS NULL OR in_user_id = ''

THEN

SET out_code = 1;

SET out_message = 'Please Enter Your First Name.';

END IF;

/*Logi Here*/

END;

我用过像

@Entity

@Table(name = "user")

@NamedStoredProcedureQueries({

@NamedStoredProcedureQuery(

name = "do_login",

procedureName = "login",

resultClasses = { LoginModel.class },

parameters = {

@StoredProcedureParameter( name = " in_user_id", type = String.class, mode = ParameterMode.IN),

@StoredProcedureParameter( name = "in_password", type = String.class, mode = ParameterMode.IN),

@StoredProcedureParameter( name = "out_code", type = Integer.class, mode = ParameterMode.OUT),

@StoredProcedureParameter( name = "out_message", type = String.class, mode = ParameterMode.OUT)

}),

})

public class LoginModel implements Serializable {

@NotEmpty

private String userid;

@NotEmpty

private String password;

//Here is getter setter

}

在我的登录控制器中,我想调用我的过程,以便可以将我的用户转发到仪表板。如果用户输入了错误的用户名或密码,我想显示过程中的消息。我在登录控制器中使用了波纹管代码

@RequestMapping(value = "/login", method = RequestMethod.POST)

public String doLogin(@ModelAttribute("webLoginForm") @Valid LoginModel registrationModel,

BindingResult bindingResult, Model model, Errors error) {

if(error.hasErrors()) {

return "login";

}

// Here I want to check My Procedure result & redirect to welcome page

//return "redirect:/welcome";

return "login";

}

我已经使用了存储库,但是这里没有写任何东西。我已经用过波纹管了..

public interface LoginRepository extends CrudRepository{

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值