我有以下场景:
在我的页面中,我有一个网格(带分页)绑定到数据源.当我点击"Extract"按钮时,网格会被填充(通过Web服务读取分页数据).然后我通过网格分页选择"第2页".再次调用Web服务以返回数据.
现在:我想再次点击"Extract",重新加载并在第一页上显示数据.我不确定哪种方式最好.
我想只调用一次服务(带输入参数),并在网格中重置分页索引.
我现在使用以下代码:
$("#btnExtract").bind("click", function(e) {
var grid = $("#section-table").data("kendoGrid");
grid.dataSource.read( {parameter: "value"} );
grid.dataSource.page(1);
});
Run Code Online (Sandbox Code Playgroud)
但实际上它会对服务进行两次调用.
我们在代码中经常使用util函数和一些功能,如Logger,EventWriter,Some Common DB调用等.我更喜欢这些函数是静态的,因为在我的每一个代码中实例化这些类中的函数都会造成严重的性能损失(是不是?!!!?,我在stackoverflow中读到过多的类实例会是一个性能打击,我正在开发一个具有大客户数据库和服务器上的高访问日志的项目.而且我遇到的static import in java看起来很酷,我想知道:在使用它之前有什么严重的考虑因素吗?
我已经从StackOverFlow收集的东西:
使用静态导入可以使代码不可读,就像判断函数定义一样.
除此之外,任何我需要担心的漂亮问题..?
旧代码:
class myservlet extends httpServlet
{
pubilc doPost()
{
Utils utils = new Utils();
DBFuncs dbFuncs = new dbFuncs();
Logger logger = new Logger();
EventWrtr eventWrtr = new EventWriter();
utils.GetEscapedName(name);
logger.Log("error");
eventWrtr.WriteEvent("something happened");
// Getting new Objects for every servlet calls
}
}
Run Code Online (Sandbox Code Playgroud)
我当前的代码:(希望这会避免不必要的实例化,代码就像上面那样,我现在正在改变它)
/* Declaring all the methods in the below classes as static methods */
import com.mycom.Utils;
import com.mycom.DBFuncs;
import com.mycom.Logger;
import com.mycom.EventWrtr;
class myservlet extends httpServlet …Run Code Online (Sandbox Code Playgroud) IntelliJ Idea在JavaScript中折叠if和其他语句,但不在Java中.我该如何获得此功能?也许你知道一些插件或设置?
WebMvcTest在我尝试加载test.properties应用@TestPropertySource注释以覆盖测试类中的某些属性时使用 Spring Boot 1.5.16 。如果我把它放在测试类上,效果就很好:
@RunWith(SpringRunner.class)
@WebMvcTest
@TestPropertySource("classpath:test.properties")
public class ControllerTest {
...
}
Run Code Online (Sandbox Code Playgroud)
但是如果我将其移动到导入的配置,则不会加载属性:
@RunWith(SpringRunner.class)
@WebMvcTest
@Import(ControllersConfiguration.class)
public class ControllerTest {
...
}
Run Code Online (Sandbox Code Playgroud)
类ControllersConfiguration是:
@TestConfiguration
@TestPropertySource("classpath:test.properties")
public class ControllersConfiguration {
...
}
Run Code Online (Sandbox Code Playgroud)
你能解释一下这种行为吗?
PS@PropertySource注释在导入的配置中工作,但优先级最低application.properties
UPD:要明确 - 尝试使所有测试通过这里: https: //github.com/Javasick/WeirdTestPropertySource
我使用 Keycloak 7.0.1 和 Spring Boot 1.5.16.RELEASE 通过指定资源、基于角色的策略和权限来保护端点 - 这按预期工作。
棘手的事情是仅保护 POST 并允许对某个特定 URI 进行 GET 请求。我在 application.yml 中做了什么:
policy-enforcer-config:
enforcement-mode: ENFORCING
paths[0]:
name: all
path: /*
paths[1]:
name: test post
path: /my/url
methods[0]:
method: GET
scopes[0]: view
methods[1]:
method: POST
scopes[0]: edit
Run Code Online (Sandbox Code Playgroud)
在 keyclaok 中,我创建了edit范围view、/my/url资源、具有角色和否定决策的策略(如果用户具有该角色 - 拒绝访问),权限包含资源、范围和策略。评估按预期进行,但我的 Spring 应用程序总是收到 403 错误。
您能否为我提供一个资源范围使用的示例,或者建议我还需要做什么才能使其正常工作?
我有一个带安全方法的服务类(@PreAuthorizeSpring Security).
编码是不好的做法?
也许我应该@PreAuthorize只在我的控制器类(@Controller或@RestController)中使用此注释
java ×3
spring-boot ×3
spring ×2
architecture ×1
import ×1
intellij-14 ×1
kendo-grid ×1
kendo-ui ×1
keycloak ×1
performance ×1
static ×1