如何更改动态 URL 的请求映射?URL 可能如下所示:
当 url 采用这种格式时,控制器的工作语法如下:
http://zz.zz.zz.com:8080/webapp/test?Id=2&maxrows=5
@RequestMapping(value = "/test", method = RequestMethod.GET)
public @ResponseBody void test(
@RequestParam(value = "Id", required = true) String Id,
@RequestParam(value = "maxrows", required = true) int maxrows
) throws Exception {
System.out.println("Id: " + Id + " maxrows: " + maxrows);
}
Run Code Online (Sandbox Code Playgroud) 我是 JavaFX 新手,目前在使用不同包中的类处理 onAction 事件时遇到一些问题。
这是包树:

这是不起作用的代码示例:
<?import java.net.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<GridPane fx:controller="GUIController.AccueilController"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
...
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="4">
<Button text="Se connecter" onAction="#handleSubmitButtonAction"/>
</HBox>
...
</GridPane>
Run Code Online (Sandbox Code Playgroud)
错误由以下人员发送:
onAction="#handleSubmitButtonAction"
Run Code Online (Sandbox Code Playgroud)
说:“处理程序方法不可访问。公开,或使用 @FXML 进行注释”
这是 AccueilController.java 文件:
package GUIController;
import java.awt.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.text.Text;
public class AccueilController {
@FXML private Text actiontarget;
@FXML protected void handleSubmitButtonAction(ActionEvent event) {
actiontarget.setText("Sign in button pressed");
}
}
Run Code Online (Sandbox Code Playgroud)
可以看到,@FXML标签被添加了,所以不知道问题出在哪里。可能有点蠢,但我真的想不通。
顺便说一句,如果没有 onAction 行,代码可以完美运行。
感谢你们 !
class l3_switch在l3_learning.py中, named中有一个方法_handle_PacketIn。现在我明白,此事件是当交换机收到与表中没有对应条目的数据包时联系控制器时的事件。
我不明白的是这里
packet = event.parsed
Run Code Online (Sandbox Code Playgroud)
现在 是什么packet.next意思isinstance(packet.next, ipv4)?
def _handle_PacketIn (self, event):
dpid = event.connection.dpid
inport = event.port
packet = event.parsed
if not packet.parsed:
log.warning("%i %i ignoring unparsed packet", dpid, inport)
return
if dpid not in self.arpTable:
# New switch -- create an empty table
self.arpTable[dpid] = {}
for fake in self.fakeways:
self.arpTable[dpid][IPAddr(fake)] = Entry(of.OFPP_NONE,
dpid_to_mac(dpid))
if packet.type == ethernet.LLDP_TYPE:
# Ignore LLDP packets
return
if isinstance(packet.next, ipv4):
log.debug("%i %i IP …Run Code Online (Sandbox Code Playgroud) 有没有办法从控制器检查当前页面?我试过
current_page?
Run Code Online (Sandbox Code Playgroud)
但这会返回一个错误:
undefined method 'current_page?'
Run Code Online (Sandbox Code Playgroud) controller ruby-on-rails ruby-on-rails-4 ruby-on-rails-5 ruby-on-rails-6
我确实买了一个便宜的控制器(Windows 认为它是 xbox 360 控制器),我想从控制器获取一些 javascript 按键事件。我确实尝试了一些在线键码测试程序,例如http://keycode.info/,但他们没有回复。我的问题是如何从 javascript 中的控制器获取键码。
请帮助我,或展示其他方法来解决此问题。
@RestController
@RequestMapping("/users")
public class UserController {
@RequestMapping("/login")
public String logIn() {
return "";
}
@RequestMapping("/getUserData")
@FilterThisRequest
public String getUserData(@PathVariable Long userId) {
return user;
}
}
Run Code Online (Sandbox Code Playgroud)
我有AuthFilter extends GenericFilterBean一个特定的逻辑。如何使过滤器仅在具有 的方法之前执行@FilterThisRequest?或者有更好的做法来解决这个问题?
因为 Laravel Nova 全局搜索忽略策略,所以我想覆盖它的控制器。不知怎的,这不起作用,全局搜索默认为Laravel\Nova\Http\Controllers\SearchController.
到目前为止我所拥有的:
app/config.php
//..
'providers' => [
//..
App\Providers\RouteServiceProvider::class,
App\Providers\NovaServiceProvider::class,
//..
],
Run Code Online (Sandbox Code Playgroud)
(请注意提供者的顺序)
routes/web.php
//..
Route::get('nova-api/search', 'SearchController@index');
Run Code Online (Sandbox Code Playgroud)
app/Http/Controllers/SearchController.php
namespace App\Http\Controllers;
use Laravel\Nova\Nova;
use Laravel\Nova\GlobalSearch;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Http\Controllers\SearchController as NovaSearchController;
class SearchController extends NovaSearchController
{
/**
* Get the global search results for the given query.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return \Illuminate\Http\Response
*/
public function index(NovaRequest $request)
{
return (new GlobalSearch(
$request, Nova::globallySearchableResources($request)
))->get();
}
}
Run Code Online (Sandbox Code Playgroud)
版本
这是行不通的。路线 …
我有UT,顺利通过
@Test
public void test() {
String text1 = "2009-07-10T14:30:01.001Z";
String text2 = "2009-07-10T14:30:01.001+03:00";
DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ");
ZonedDateTime zonedDateTime1 = ZonedDateTime.parse(text1, f);
ZonedDateTime zonedDateTime2 = ZonedDateTime.parse(text2, f);
System.out.println(zonedDateTime1);
System.out.println(zonedDateTime2);
}
Run Code Online (Sandbox Code Playgroud)
输出是
2009-07-10T14:30:01.001Z
2009-07-10T14:30:01.001+03:00
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在 spring-controller 上使用这种模式时
@GetMapping
public ResponseEntity get( @RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ")
ZonedDateTime start) {
Dto result = service.get(start);
return new ResponseEntity(result, getHeaders(), HttpStatus.OK);
}
Run Code Online (Sandbox Code Playgroud)
例如,仅当我传递 Z 而不是时区时,它才有效
2009-07-10T14:30:01.001Z
Run Code Online (Sandbox Code Playgroud)
但是当尝试传递时区偏移时 - 出现错误消息
“无法将类型“java.lang.String”的值转换为所需类型“java.time.ZonedDateTime”;嵌套异常为 org.springframework.core.convert.ConversionFailedException:无法从类型 [java.lang.String] 转换输入 [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.time.ZonedDateTime] 获取值 '2009-07-10T14:30:01.001 03:00';嵌套异常是 java.lang.IllegalArgumentException:解析尝试失败的值 [2009-07-10T14:30:01.001 03:00]”,
我尝试像这样通过邮递员传递请求
POST …Run Code Online (Sandbox Code Playgroud) 我正在尝试获取当前用户 ID,以便我的事件索引页面将仅显示来自当前用户的事件。
我的 HttpContext.User 在我的事件控制器的索引内出现错误“无法从 System.security.claims.claimsPrincipal 转换为 Scheduler.Areas.Identity.Data”。
var userId = await _userManager.GetUserIdAsync(HttpContext.User);
Run Code Online (Sandbox Code Playgroud)
这是我的 EventsController 中的代码:
public EventsController(SchedulerDbContext context, UserManager<SchedulerUser> userManager)
{
_context = context;
_userManager = userManager;
}
// GET: Events
[Authorize]
public async Task<IActionResult> Index()
{
var userId = await _userManager.GetUserIdAsync(HttpContext.User);
return View(await _context.Events.Where(g => g.SchedulerUser == userId).ToListAsync());
}
Run Code Online (Sandbox Code Playgroud)
我应该去哪里寻找解决这个问题的方法?如果需要,我将更新更多代码。
我正在尝试在 ASP.NET core 5 Razor Pages Web 应用程序中创建 API 控制器。
我已在 Visual Studio 中命名的文件夹内创建了 Api 控制器Api。
然后,当我尝试运行以下 url 来测试 api 控制器是否正常工作时,我收到 404 not found:
https://localhost:345345/api/saveimage
我缺少什么?
Api 控制器(SaveImageController.cs):
[Route("api/[controller]")]
[ApiController]
public class saveImageController : ControllerBase
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "test", "test2" };
}
}
Run Code Online (Sandbox Code Playgroud) c# controller asp.net-apicontroller razor-pages asp.net-core-5.0
controller ×10
java ×3
spring-boot ×2
asp.net-core ×1
c# ×1
filter ×1
fxml ×1
identity ×1
javafx ×1
javascript ×1
keycode ×1
laravel ×1
mininet ×1
openflow ×1
overriding ×1
pox ×1
python ×1
razor-pages ×1
spring ×1
spring-mvc ×1
xbox360 ×1