使用这篇文章中的“从控制器生成图像”答案,我创建了一个控制器操作来返回图表图像,如下所示(X 和 Y 值只是作为测试数据):
public FileContentResult HistoryChart()
{
Chart chart = new Chart();
string[] currencies = { "ZAR", "USD", "GBP", "JPY" };
foreach (string currency in currencies)
{
Series series = new Series(currency);
series.ChartType = SeriesChartType.FastLine;
for (int x = 0; x <= 30; x++)
series.Points.AddXY(x, (x * 5));
chart.Series.Add(series);
}
using (MemoryStream ms = new MemoryStream())
{
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "image/png", "mychart.png");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,控制器返回的图像是空白的(尽管它确实返回图像)
我希望它是我遗漏的一些简单的东西!任何意见将不胜感激,谢谢。
asp.net-mvc controller image mschart microsoft-chart-controls
我希望我的欢迎控制器使用不同的布局:
class WelcomeController < ApplicationController
def index
if signed_in?
layout 'default'
else
layout 'welcome'
end
render 'welcome/index'
end
end
Run Code Online (Sandbox Code Playgroud) 所以我尝试使用WINDOW_SHOWN如下代码处理来自控制器的事件:
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
initializeDatePickers();
System.out.println("payer number in initialize: " + payerNumber);
URL location = getClass().getResource("/createUser.fxml");
FXMLLoader loader = new FXMLLoader();
try {
Parent root = (Parent) loader.load(location.openStream());
root.getScene().getWindow().setOnShown(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.out.println("ONSHOWN");
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
但我所得到的只是无休止的循环和程序崩溃。下面的代码也不起作用,它返回 NullPointerException:
@FXML private AnchorPane createUserDialog; //my root pane
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
createUserDialog.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_SHOWN,
new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent …Run Code Online (Sandbox Code Playgroud) Too few arguments to function Illuminate\Routing\PendingResourceRegistration::name(),
1 passed in C:\xampp\htdocs\project\routes\web.php on line 18
and exactly 2 expected.
Run Code Online (Sandbox Code Playgroud)
我在 laravel 上尝试 Klorofil 模板,但它的工作完美。我不知道为什么,但我好几次都没有打开 laravel 和 php。当我再次打开这个项目时,这正在发生。我只记得也许我更改了路由或控制器,因为我想在没有刷新和错误的情况下使用 ajax,而我忘记像以前一样更改。但是什么时候再次搜索这个模板可能不是我的错...或者php有更新。
网页.php
Route::get('/', function () {
return view('main');
});
Route::resource('siswa', 'SiswaController')->name('siswa');
Route::get('/login','AuthController@login')->name('login');
Route::post('/postlogin', 'AuthController@postlogin');
Route::get('/logout','AuthController@logout');
Route::get('/dashboard', 'DashboardController@index')->middleware('auth');
Route::get('siswa.index', 'SiswaController@index')->middleware('auth');
Route::post('siswa.index/import', 'SiswaController@import')->middleware('auth');
Run Code Online (Sandbox Code Playgroud)
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Siswa;
use DB;
use Excel;
class SiswaController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{ …Run Code Online (Sandbox Code Playgroud) 根据教程测试 Web 层,可以使用以下代码测试控制器是否已创建:
@Test
public void contexLoads() throws Exception {
assertThat(controller).isNotNull();
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
The method assertThat(T, Matcher<? super T>) in the type Assert is not applicable for the arguments (HomeController)"
Run Code Online (Sandbox Code Playgroud)
即使声明:
import static org.junit.Assert.assertThat;
Run Code Online (Sandbox Code Playgroud)
我的类的代码与示例中给出的代码相同:
package com.my_org.my_app;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SmokeTest {
@Autowired
private HomeController controller;
@Test
public void contexLoads() throws Exception {
assertThat(controller).isNotNull();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我将断言语句更改为:
@Test
public void contexLoads() throws Exception { …Run Code Online (Sandbox Code Playgroud) 我正在制作一个电子邮件字段,我想避免或自动删除其中的前导和尾随空格。
我尝试使用
myTextFieldController.addListener(() { myTextFieldController.text = myTextFieldController.text.trim(); });
Run Code Online (Sandbox Code Playgroud)
但是只要用户输入任何字符,它就会将光标移动到开头。
还有什么办法吗?
您了解用户,所以我需要将其删除,否则他们将永远留在那里尝试验证该字段。
当然,我知道我可以在验证之前做到这一点,但我想知道是否有更强大的方法。
我想在服务层抛出异常:
List<String> cellValuesOfTheRow = getColumnValuesForRow(row, false);
logger.info("currentRowNumber: {}, cellValuesOfTheRow: {}", currentRowNumber, cellValuesOfTheRow);
if (cellValuesOfTheRow.contains(null)) {
throw new NullFieldValueException(currentRowNumber);
}
Run Code Online (Sandbox Code Playgroud)
如果该列表包含空值,我希望它抛出异常。
我做了一个自定义例外:
public class NullFieldValueException extends RuntimeException {
private static final long serialVersionUID = -8460356990632230194L;
int currentRowNumber;
public NullFieldValueException(int currentRowNumber) {
super();
this.currentRowNumber = currentRowNumber;
}
}
Run Code Online (Sandbox Code Playgroud)
我也有控制器建议:
List<String> cellValuesOfTheRow = getColumnValuesForRow(row, false);
logger.info("currentRowNumber: {}, cellValuesOfTheRow: {}", currentRowNumber, cellValuesOfTheRow);
if (cellValuesOfTheRow.contains(null)) {
throw new NullFieldValueException(currentRowNumber);
}
Run Code Online (Sandbox Code Playgroud)
这是来自messages/messages_en.properties:
#nullpointer
error.null.field.value=Empty or null value for the row number: {0} …Run Code Online (Sandbox Code Playgroud) 这是一个返回所有区对象的控制器
CORS 策略已阻止在 ' http://localhost:8080/从源 ' http://localhost:3000 '访问 XMLHttpRequest :请求的资源上不存在 'Access-Control-Allow-Origin' 标头。
package com.ministry.demo.controller;
import com.ministry.demo.model.District;
import com.ministry.demo.repository.DistrictRepository;
import com.ministry.demo.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(path = "district")
public class DistrictController {
@Autowired
DistrictService service;
@GetMapping(path = "getAll")
List<District> getAllDistrict(){
return service.getAllDistricts();
}
}
Run Code Online (Sandbox Code Playgroud) 我不确定为什么会发生这种情况,但在我下面显示的代码中,它表示当前上下文中不存在“Ok”,但是当我向代码添加异步时,错误消失并再次运行. 我没有放置等待或任何东西,它只是异步。工作人员发出警告,就像它应该的那样,但由于某种原因它使它起作用,有谁知道为什么,我该如何解决这个问题?
不工作:
public Task<IActionResult> GetBusinesses()
{
var events = _context.Businesses.Include(p => p.Locations).ToList();
return Ok(events);
}
Run Code Online (Sandbox Code Playgroud)
在职的:
public async Task<IActionResult> GetBusinesses()
{
var events = _context.Businesses.Include(p => p.Locations).ToList();
return Ok(events);
}
Run Code Online (Sandbox Code Playgroud) 我有一个名为“GebruikersController”的控制器类
当我使用“ https://localhost:5001/Gebruikers ”我得到正确的输出但是当我使用“ https://localhost:5001/api/GebruikerController/Gebruikers ”(它应该如何工作?)我得到一个空白页. 有谁能够帮助我?谢谢!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using RESTAPI.Data;
using RESTAPI.Data.Repositories;
using RESTAPI.DTOs;
using RESTAPI.Models;
namespace RESTAPI.Controllers
{
[ApiConventionType(typeof(DefaultApiConventions))]
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class GebruikersController : ControllerBase
{
private readonly IGebruikerRepository _gebruikerRepository;
public GebruikersController(IGebruikerRepository context)
{
_gebruikerRepository = context;
}
// GET: api/Gebruikers
/// <summary>
/// Geeft alle gebruikers geordend op achternaam
/// </summary>
/// <returns>array van gebruikers</returns>
[HttpGet("/Gebruikers")]
public IEnumerable<Gebruiker> GetGebruikers()
{
return _gebruikerRepository.GetAlleGebruikers().OrderBy(d => d.Achternaam);
}
// GET: …Run Code Online (Sandbox Code Playgroud) controller ×10
c# ×2
java ×2
spring-boot ×2
.net ×1
asp.net-core ×1
asp.net-mvc ×1
exception ×1
flutter ×1
image ×1
javafx-2 ×1
laravel ×1
layout ×1
mschart ×1
php ×1
reactjs ×1
resources ×1
routes ×1
ruby ×1
spring ×1
textfield ×1
unit-testing ×1