Spring中的die()等效于什么? [英] What is the equivalent of die() in Spring?

查看:60
本文介绍了Spring中的die()等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP 中,有一个 die("some message"); 用于编写输出并停止脚本的执行.那么 Spring mvc (在 Controller JSP 中)是否有一个等效项?

In PHP there is the die("some message"); to write output and stop the execution of the script. So is there an equivalent in Spring mvc ( in Controller and in the JSP ) ?

推荐答案

在Java/JSP中没有理由使用die()之类的东西.JSP应该用作纯视图技术.它应该只生成HTML.不要尝试访问数据库,读取文件或其他.这就是用Java编写的控制器的工作

There is no reason to have something like die() in Java/JSPs. JSPs should be used as a pure view technology. It should just generate HTML. Not try to access a database, read files or whatnot. That is the job of a controller, written in Java

使用 System.exit(0); 退出Java代码.

Use System.exit(0); to exit the java code.

请注意,这将停止当前正在运行的JVM实例.

Keep a note this will stop the JVM instance which is currently running.

如果您想使用一种方法,请使用return或throw异常来展示错误情况.

If you want to come out of a method use return or throw exception to showcase error condition.

这篇关于Spring中的die()等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆