问题标签 [request-mapping]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 如何以编程方式读取休息服务的路径?
假设我定义了以下简单的休息:
有没有办法通过代码的另一部分(即完全从不同的方法)读取路径字符串?就像是:
WDYT?谢谢!
解决了! 这是我需要的实现:
spring-mvc - 通过 Java REST Api 中的 POST 请求传输 .xls 文件
我是 Spring 新手,在通过 POST 请求从前端接收 .xls 文件时遇到了一些麻烦。基本上,当我访问“项目/文件”链接时,我收到错误代码 400(错误请求),但前端和后端的参数名称相同。
到目前为止,这是我的代码:
谁能给我一个想法如何解决这个问题?
spring - Spring mvc:我无法将表单操作 url 映射到控制器操作
如果已经问过这个或类似的问题,我提前道歉,但我找不到合适的答案。
我有一个像这样的简单形式EditUser.jsp
(映射到:).../admin/users/edit/{userId}
:
像这样@RequestMapping
:
问题是请求的结果:HTTP Status 404 - /admin/users/edit/addRole/7
-“请求的资源不可用”(7 是一些用户 ID)。A 无法将POST
请求映射到控制器操作。我已经尝试过,th:action
但它会将我重定向到上一页.../admin/users
。
任何帮助指针表示赞赏。
spring-mvc - spring mvc请求方法404错误
}
当我查看http://localhost:8080/ProjectName/greet.json/hello 和http://localhost:8080/ProjectName/greet.json/word 时无法执行 syso 方法
AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,businessService,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor#0,txAdvice,org.springframework.context.annotation。 ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; 工厂层次结构的根 08:33:38,490 错误 [org.springframework.web.servlet.DispatcherServlet] (org.springframework.web.servlet.FrameworkServlet:460) - 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建错误在 ServletContext 资源 [/WEB-INF/web-config.xml] 中定义的名称为 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0' 的 bean:调用 init 方法失败;嵌套异常是java。lang.IllegalStateException:发现不明确的映射。无法将 'userAction' bean 方法 public void cn.elfsoft.controller.UserAction.word(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 映射到 {[/greet.json],methods=[],params =[],headers=[],consumes=[],produces=[],custom=[]}: 已经有 'userAction' bean 方法 public void cn.elfsoft.controller.UserAction.hello(javax.servlet.http .HttpServletRequest,javax.servlet.http.HttpServletResponse) 映射。
java - getResourceAsStream 返回 NullpointerException
在 Spring 中,我想让图像显示在我的浏览器上。该图像位于我的主要项目中,即
这意味着 img.png 位于根目录中,因此我不提供任何路径,但它返回一个NullPointerException
. 我尝试在 src 中添加图像,我将路径更改为src\img.png
但仍然给了 NPE。
请注意,这个项目使用的是 Maven。
堆栈跟踪:
这是我使用的代码:
对这个问题的评论被标记为关闭:
- 这个问题与编程有关,因为 API getResourceAsStream说:
如果没有找到具有此名称的资源,则返回 URL 对象或 null
null
即使我尝试添加img.png
到不同的位置,我的代码也会返回。
- 这个问题不是这个问题的重复:getResourceAsStream() is always return null
该问题的答案说该文件必须与this
该问题位于同一目录中,即使我将图像添加到类所在的同一位置DataService
,它也不起作用。
java - RequestMapping 返回 404 错误
是的,我知道——有很多这样的问题。我试图扫描所有这些,但没有帮助我。这是我的代码:
调度程序 servlet
web.xml
控制器:
文件位置
HomeController 位于 com.package.controller 包中。
index.jsp 位于 WEB-INF/jsp/ 包中。
我试图访问的 URL 是:localhost:8080/hello.do
我究竟做错了什么?感谢帮助!
rest - Rest path for application
I'm fairly new to Spring Boot, but I want to want to build my application in such a way, that can deploy mulitple applications on the same server and i want to distinguish the applications in the rest path.
For example, say i have the applications user-management and animal-management and i have a rest-controller in both of them responding to the path \names
.
Both those applications run on localhost:8080
so when sending a GET
to localhost:8080/users/names
, I want the controller of the user-management to react and the same for animal with a GET
to localhost:8080/animals/names
.
I can put a @RequestMapping
on the controller to acchieve the names
part, but if i do the same on the application, it gets ignored.
Basically I want to tell my application "Every controller in this application should be mapped to the rest path specified on the controller, but prefixed with 'x'".
How can I do that.
json - NodeEntity 不会持续存在
我有以下 NodeEntity:
User
在哪里
和BookRepository
我已经构建了一个简单的 Rest-Controller 来将 a 存储Book
在数据库中。
当我现在POST
预订 JSON
对于控制器,发生了两件事让我感到困惑:首先,book-object 中的 author 是 null,尽管 theBook
和 theUser
都有它们的默认构造函数。其次:这本书没有得到持久化。没有错误,我只是返回了相同的书对象(作者仍然为空),但 ID 仍然为空。MATCH n RETURN n
在 neo4j 客户端上查询也不会产生任何结果。
我尝试User
从 `Book 中删除对象,认为故障在那里,但我仍然得到相同的行为。我究竟做错了什么?
java - 当RequestMapping放在类的顶部时如何实现POST-GET-REDIRECT?
我在类级别放置了 RequestMapping 注释:
我的方法用 renderMapping 注释:
问题是,在调用myAction()
and之后returning to home page
,当按下 时F5
,又是这个方法called
,所以我想实现该Post/Redirect/Get
模式,但是我找到的所有解决方案都stackoverflow
与修改 相关RequestMapping
,我做不到,因为它处于class
水平状态,并且还有class
很多其他的methods
。
有谁知道在这种情况下该怎么做?
spring - 如何将用户定义的属性值应用于@RequestMapping
我有几个@RequestMapping
值会在某一天从“/XXX”变为“/V100”。所以我需要在属性中定义它。我已经用谷歌搜索了,并且有使用 application.properties 的方法,但我必须将“/XXX”值保留在用户定义的属性中,如“local.properties”。是否可以@RequestMapping
在用户定义的属性上定义值?
**更新:尝试了几个小时并让它工作。
我的属性
mvc-context.xml
控制器
Tomcat日志