trim()在这里,我的函数值存在问题PostgreSQL:
Ruby代码:
if(this.modelName=="ClientOffice")
{ this.params="model_name="+this.modelName+"&action_name="+this.actionName+"&
find_condition=btrim(clients_corporate_billings.id,' ') %3D
btrim('"+validString('populateValue0','text')+"',' ')
& object_id="+this.objectId;
}
Run Code Online (Sandbox Code Playgroud)
&action_name="+this.actionName+"
&find_condition=btrim(clients_corporate_billings.id,' ') %3D
btrim('"+validString('populateValue0','text')+"',' ')
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,btrim是functionPostgreSQL 进行修剪,但它给出/产生错误。
我的控制器中有两种方法用于查找用户(注意范围enabled_only):
before_filter :find_user, :only => :show
before_filter :find_any_user, :only => [:edit, :update, :destroy]
def find_user
@user = User.enabled_only.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:alert] = "The user you were looking for could not be found"
redirect_to root_path
end
def find_any_user
@user = User.find(params[:id])
rescue ActiveRecord::RecordNotFound
flash[:alert] = "The user you were looking for could not be found"
redirect_to root_path
end
Run Code Online (Sandbox Code Playgroud)
当然,这些可以合并到一种检查是否存在错误的方法中,:action == 'show'但我无法采取救援措施来捕获错误。我尝试了类似以下的方法,但没有成功:
before_filter :find_user, :only => [:show, :edit, :update, :destroy]
def find_user
@user = if :action == 'show' …Run Code Online (Sandbox Code Playgroud) 我的 grails 控制器由以下 URL 调用
/center/madrid/12-de-octubre
/center/madrid/12-de-octubre?opt=1
Run Code Online (Sandbox Code Playgroud)
如果 ? 之后有任何参数,我需要控制器表现不同。在网址中
我有以下 URL 映射:
name center: "/center/$_uni_city/$_uni_facility_name" {
controller = "site"
action = "centerprofile"
}
Run Code Online (Sandbox Code Playgroud)
虽然我可以找到所有参数(例如 _uni_city=Madrid、opt=1),但在应用 URLMappings(即上面示例中的 opt)后,我无法确定哪些参数来自查询字符串。
有没有办法在 grails 控制器中检索原始请求 URL(即/center/madrid/12-de-octubere?opt=1)?
在我的控制器中,我有一个 after_action 块。当有问题的方法失败时,我想停止 after_action 的运行。
导轨 4.2,红宝石 2.2
有谁知道如何在rails中做到这一点?
class MyController < ApplicationController
after_action only: :show do
# do so and so
end
def show
begin
# something really bad happens here... My Nose!
rescue => e
# how do I stop after_action from running?
flash[:error] = 'Oh noes... Someone make a log report'
redirect_to '/'
return
end
# yarda yarda yarda
end
end
Run Code Online (Sandbox Code Playgroud) 我想模拟一些 JSON(我正在从文件中读取),并将其作为某些 Spring Controller 的结果返回。
文件中当然包含正确的 JSON 数据格式,例如:
{"country":"","city":""...}
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像:
@RestController
@RequestMapping("/test")
public class TestController {
@Value("classpath:/META-INF/json/test.json")
private Resource testMockup;
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody JSONObject getTest() throws IOException {
JSONObject jsonObject = new JSONObject(FileUtils.readFileToString(testMockup.getFile(), CharEncoding.UTF_8));
return jsonObject;
}
}
Run Code Online (Sandbox Code Playgroud)
读取文件本身等jsonObject本身没有问题,
调试 PoV 是正确的,但是我从浏览器获取HTTP 状态 406。我也试过只返回 String (通过返回jsonObject.toString()),而不是JSONObject. 然而,它会导致编码问题 - 因此来自浏览器的 JSON 不是 JSON 本身(一些额外的斜杠、引号等)。
有什么办法可以从文件中返回 JSON?
我有控制器,我需要从另一个控制器访问操作并返回数据:
rest/controllers/AController
switch (@$_GET['barcodeType'])
{
case '1D':
{
//do action Request1 from BController and return data from
this controller
}
break;
case '2D':
{
//do action Request2 from BController and return data from
this controller
}
break;
default:
return ['Wrong barcodeType'];
break;
}
Run Code Online (Sandbox Code Playgroud)
soap/controllers/BController
public actionRequest1{
//do something and return data to AController
}
public actionRequest2{
//do something and return data to AController
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个具有多个端点的 Spring REST 控制器类。从另一个端点直接调用端点方法是一种好习惯吗?
我已经用谷歌搜索了它,但没有找到任何关于处理这个问题的好做法的答案。
@RestController
public class DataContoller {
@GetMapping("/dataA/{param}")
public ResponseEntity getDataA(@PathVariable String param) {
// logic to fetch data A
return ResponseEntity.ok("A");
}
@GetMapping("/dataB/{param}")
public ResponseEntity getDataB(@PathVariable String param) {
ResponseEntity response = getDataA("test");
String result = response.getBody();
return ResponseEntity.ok("B" + result);
}
}
Run Code Online (Sandbox Code Playgroud)
原则上它是有效的,因为它只是来自另一个方法的方法调用,但我想知道这是否是一个好习惯。如果这不是好的做法,那么理想的做法是什么。一种选择是使用 RestTemplate。这是唯一的选择吗?
Angular 客户端- httpClient 发送请求
const map: Map<string, string> = new Map<string, string>();
map.set('foo', 'bar');
this.http.post(address, map, httpOptions).subscribe(
next => console.log('next: ' + next),
error => console.log('error: ' + error),
() => console.log('complete')
);
Run Code Online (Sandbox Code Playgroud)
Springboot 服务器-控制器接收请求
@RequestMapping(value = "/foobar", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public void fooBar(@RequestBody Map<String, String> foo){
System.out.println(foo.entrySet()); //<-- always empty
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Rails 5。我有这个控制器......
class MyObjectsController < ApplicationController
def create
my_object = MyService.build(create_params)
Run Code Online (Sandbox Code Playgroud)
我想在 rails 控制台中调用 create 方法,但出现此错误...
irb(main):007:0> MyObjectsController.new.create(:id => "abc")
Traceback (most recent call last):
2: from (irb):7
1: from app/controllers/my_objects_controller.rb:4:in `create'
ArgumentError (wrong number of arguments (given 1, expected 0))
Run Code Online (Sandbox Code Playgroud)
如何将参数传递给我的控制器方法?
我正在使用 React Hook Forms。
<Controller
control={control}
rules={{ required: "Required" }}
error={errors.state ? true : false}
helperText={errors.state && errors.state.message}
name="state"
as={
<AutoComplete
options={stateOptions}
onChange={selectStateHandler}
label="State"
value={selectedState}
/>
}
/>
Run Code Online (Sandbox Code Playgroud)
辅助文本正在使用TextField但不与Autocomplete. TextField边框颜色因错误而变化,我想要与Autocomplete.
controller ×10
java ×3
spring ×3
action ×1
angular ×1
console ×1
dictionary ×1
forms ×1
json ×1
jsonobject ×1
material-ui ×1
php ×1
postgresql ×1
reactjs ×1
rescue ×1
rest ×1
return ×1
sql ×1
url-mapping ×1
yii2 ×1