controller

Mockito Exception - when() requires an argument which has to be a method call on a mock

 ̄綄美尐妖づ 提交于 2019-12-18 03:01:41
问题 I have a very simple test case that is using Mockito and Spring Test framework. When I do when(pcUserService.read("1")).thenReturn(pcUser); I get this exception. org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles); Also, this error might show up because: 1. you stub either of: final/private/equals()/hashCode() methods. Those methods *cannot* be

How to return a html page from a restful controller in spring boot?

倖福魔咒の 提交于 2019-12-17 23:40:44
问题 I want to return a simple html page from controller, but I get only the name of the file not its content. Why? This is my controller code: @RestController public class HomeController { @RequestMapping("/") public String welcome() { return "login"; } } This is my project structure: [ 回答1: When using @RestController like this: @RestController public class HomeController { @RequestMapping("/") public String welcome() { return "login"; } } This is the same as you do like this in a normal

ASP.NET MVC: returning plaintext file to download from controller method

会有一股神秘感。 提交于 2019-12-17 22:54:44
问题 Consider the need to return a plain-text file from a controller method back to the caller. The idea is to have the file downloaded, rather than viewed as plaintext in the browser. I have the following method, and it works as expected. The file is presented to the browser for download, and the file is populated with the string. I'd like to look for a 'more correct' implementation of this method, as I am not 100% comfortable with the void return type. public void ViewHL7(int id) { string

Exception handling in Grails controllers

微笑、不失礼 提交于 2019-12-17 18:35:02
问题 I know how to do generic exception handling in Grails using UrlMappings and an ErrorController for generic exception handling, so that if an exception escapes a controller the user will be sent to a generic error page and the exception will be logged. I also know how to use try/catch blocks to handle specific exceptions and attempt to recover from them. But in most controllers, I just want to give the user a slightly more specific error message if an exception occurs. So in the create action,

AngularJS: How to pass arguments/functions to a directive?

大憨熊 提交于 2019-12-17 17:50:08
问题 Look at this Fiddle, what do I have to change, that the expressions in the template get evaluated using the arguments I defined in the HTML? The SAVE-button should call the blabla() -function of the controller, since I pass it? var myApp = angular.module('MyApp',[]) myApp.directive('editkeyvalue', function() { return { restrict: 'E', replace: true, scope: { accept: "expression" }, template : '<div><label class="control-label">{{key}}</label>' + '<label class="control-label">{{key}}</label>' +

Laravel: Load method in another controller without changing the url

依然范特西╮ 提交于 2019-12-17 17:36:20
问题 I have this route: Route::controller('/', 'PearsController'); Is it possible in Laravel to get the PearsController to load a method from another controller so the URL doesn't change? For example: // route: Route::controller('/', 'PearsController'); // controllers class PearsController extends BaseController { public function getAbc() { // How do I load ApplesController@getSomething so I can split up // my methods without changing the url? (retains domain.com/abc) } } class ApplesController

How to make a REST API first web application in Laravel

旧时模样 提交于 2019-12-17 17:30:38
问题 I want to make an API first application in Laravel. I don't know what is the best approach to do this, I will explain what I am trying to do, but please feel free to give answers how to do this in a different way. I don't want all my frontend to be written in javascript and parse the JSON output of the API with angular.js or something similar. I want my Laravel application to produce the HTML views. I am trying to go down the road of having two controllers one on for the API and one for the

Spring Controller to handle all requests not matched by other Controllers

本小妞迷上赌 提交于 2019-12-17 16:21:21
问题 I have a series of Controllers with Request Mappings that match certain URL's. I also want a Controller that will match any other URL not matched by the other Controllers. Is there a way to do this in Spring MVC? For example, could i have a controller with @RequestMapping(value="**") and change the order in which Spring Controllers are processed so this Controller is processed last to catch all unmatched requests? Or is there another way to achieve this behaviour? 回答1: If your base url is

Passing parameters from view to controller

怎甘沉沦 提交于 2019-12-17 16:19:42
问题 I got a bit of a newbie question. I'm trying to pass a variable from my view to my controller. Is there anyway my method in my controller can receive variables from my view? Post view: show.html.erb: .... <%=link_to "Add relationship", :method => :add_relationship(@rela) %> Controller: post.controller.rb: def add_relationship(rela) @post = Post.find(params[:id]) if current_user.id == @post.user_id @post.rel_current_id = rela.id @post.save redirect_to relationships_url else redirect_to posts

Where to render comments controller in Rails on model validations failure?

假如想象 提交于 2019-12-17 16:10:55
问题 I have a simple Video model in my rails app that has_many comments. I am displaying these comments on the video's show page. When I submit the form everything works fine; however, if there are validation errors on the Comment model, then my system blows up. If there are validation errors on the Comment model, I would simply like to render the video's show page again, with the validation error styling showing. How do I do this inside of my create action? Thanks a lot! class CommentsController