我需要扩展现有的控制器并为其添加一些功能.但是作为一个项目要求我无法触及原始控制器,问题是该控制器上有一个@RequestMapping注释.所以我的问题是如何才能请求/someUrl转到我的新控制器而不是旧控制器.
这是一个例子,只是为了澄清我在说什么:
原控制器:
@Controller
public class HelloWorldController {
@RequestMapping("/helloWorld")
public String helloWorld(Model model) {
model.addAttribute("message", "Hello World!");
return "helloWorld";
}
}
Run Code Online (Sandbox Code Playgroud)
新控制器:
@Controller
public class MyHelloWorldController {
@RequestMapping("/helloWorld")
public String helloWorld(Model model) {
model.addAttribute("message", "Hello World from my new controller");
// a lot of new logic
return "helloWorld";
}
}
Run Code Online (Sandbox Code Playgroud)
如何在不编辑的情况下覆盖原始映射HelloWorldController?
我有两个不同的数据库模式中定义的相同表类型.当我尝试从一个模式调用SP到另一个模式作为参数传递类型时,我收到以下错误:
"操作数类型冲突myCustomType与myCustomType不兼容"
我有以下代码:
CREATE TYPE myCustomType AS TABLE
(
somevalue INT,
somevalue2 INT
);
Run Code Online (Sandbox Code Playgroud)
USE DB1
GO
CREATE PROC1(
@myVar myCustomType READONLY
)
AS
BEGIN
EXEC db2.dbo.PROC2 @myVar
END
GO
USE DB2
GO
CREATE PROC2(
@myVar myCustomType READONLY
)
AS
BEGIN
--do something with myVar
END
Run Code Online (Sandbox Code Playgroud)
USE db1
GO
DECLARE @myVar myCustomType
INSERT into @myVar(1,2)
EXEC PROC1 @myVar
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
您好,我正在尝试使用 proxyquire 模拟控制器内的模型。但由于某种原因,当尝试注入模拟时,原始文件被调用。
这就是控制器内部需要我的模型的方式:
var Product = require('./product.model');
Run Code Online (Sandbox Code Playgroud)
这就是我尝试存根模型的方式
var proxyquire = require('proxyquire').noCallThru().noPreserveCache();
var productsStub = {findAsync: sinon.stub()};
productsStub.findAsync.resolves(mockProducts);
var mockProducts = [{_id:'0001',title: 'title', price: 123, description: 'le description'}];
var productController = proxyquire('./product.controller',{'./product.model':productsStub});
Run Code Online (Sandbox Code Playgroud)
但是当我运行测试时我收到此错误
Running "mochaTest:unit" (mochaTest) task
>> Mocha exploded!
>> OverwriteModelError: Cannot overwrite `Product` model once compiled.
>> at Mongoose.model (/Users/victor/Documents/projects/estudo/mean/meanshop/node_modules/mongoose/lib/index.js:360:13)
>> at Object.<anonymous> (/Users/victor/Documents/projects/estudo/mean/meanshop/server/api/product/product.model.js:15:27)
>> at Module._compile (module.js:409:26)
>> at normalLoader (/Users/victor/Documents/projects/estudo/mean/meanshop/node_modules/babel-core/lib/api/register/node.js:199:5)
>> at Object.require.extensions.(anonymous function) [as .js] (/Users/victor/Documents/projects/estudo/mean/meanshop/node_modules/babel-core/lib/api/register/node.js:216:7)
>> at Module.load (module.js:343:32)
>> at Function.Module._load (module.js:300:12) …Run Code Online (Sandbox Code Playgroud) 有谁知道为什么这个正则表达式没有返回任何匹配?
local = u'Rua Engenheira Enedina Alves Marqu\xeas, 126 - Cajuru, Cajuru, Curitiba - PR'
p = re.compile(ur'\d[ ]+?-(.*?)(?:,|-)')
matches = re.match(p,local)
Run Code Online (Sandbox Code Playgroud)
当我在任何正则表达式测试工具中尝试这个正则表达式它返回我想要的东西时,我想要捕获这个单词
卡茹鲁
java ×1
mocha.js ×1
node.js ×1
proxyquire ×1
python ×1
regex ×1
spring-mvc ×1
sql ×1
sql-server ×1