我正在尝试重定向,而不将参数添加到我的URL.
@Controller
...
public class SomeController
{
...
@RequestMapping("save/")
public String doSave(...)
{
...
return "redirect:/success/";
}
@RequestMapping("success/")
public String doSuccess(...)
{
...
return "success";
}
Run Code Online (Sandbox Code Playgroud)
重定向后,我的网址看起来总是这样:.../success/?param1=xxx¶m2=xxx.由于我希望我的URL有点RESTful,并且在重定向后我从不需要params,我不希望它们被添加到重定向上.
任何想法如何摆脱它们?
由于WS客户端服务和端口的初始化需要很长时间,所以我喜欢在启动时初始化它们并重用相同的端口实例.初始化看起来像这样:
private static RequestContext requestContext = null;
static
{
MyService service = new MyService();
MyPort myPort = service.getMyServicePort();
Map<String, Object> requestContextMap = ((BindingProvider) myPort).getRequestContext();
requestContextMap = ((BindingProvider)myPort).getRequestContext();
requestContextMap.put(BindingProvider.USERNAME_PROPERTY, uName);
requestContextMap.put(BindingProvider.PASSWORD_PROPERTY, pWord);
rc = new RequestContext();
rc.setApplication("test");
rc.setUserId("test");
}
Run Code Online (Sandbox Code Playgroud)
我班上某个地方的电话:
myPort.someFunctionCall(requestContext, "someValue");
Run Code Online (Sandbox Code Playgroud)
我的问题:这个调用是否是线程安全的?
我的目标是过滤最佳匹配.在我的例子中,我有一个人员列表,我想按姓氏和名字过滤.
匹配的优势将是:
我的代码到目前为止:
final List<Person> persons = Arrays.asList(
new Person("Doe", "John"),
new Person("Doe", "Jane"),
new Person("Munster", "Herman");
Person person = persons.stream().filter(p -> p.getSurname().equals("Doe")).???
Run Code Online (Sandbox Code Playgroud) 目前我有一个Web应用程序,我们使用web.xml来配置应用程序.web.xml有welcome-file-list.
<web-app>
...
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我们计划使用spring框架并使用java类进行应用程序配置.
class MyApplication extends WebApplicationInitializer {
public void onStartUp(ServletContext context){
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何在此java类中指定welcome-file-list?
我在这里有一个非常天真的概念问题需要澄清.在我的应用程序中,我目前正在使用JSR 303 Hibernate Validator来验证带有@NotBlank和@NotNull注释的域模型,比如检查用户名,密码等.
public class Admin {
private Long id;
@NotBlank(message = "Username should not be null")
private String username;
@NotBlank(message = "Username should not be null")
private String password;
...
Run Code Online (Sandbox Code Playgroud)
但是为了验证像现有用户名这样的域逻辑,我仍然使用Spring的Validator接口
@Component
public class AdminValidator implements Validator {
...
@Override
public void validate(Object target, Errors errors) {
Admin admin = (Admin) target;
if (usernameAlradyExist())){
errors.rejectValue("username", null, "This user already exist's in the system.");
}
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,我正在使用它们
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@Valid @ModelAttribute("admin") Admin admin, …Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以将这段xml配置映射到Spring JavaConfig:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"
default-autowire="byName">
<aop:config>
<aop:pointcut id="serviceAnnotatedClass" expression="@within(org.springframework.stereotype.Service)" />
<aop:advisor id="managerTx" advice-ref="txAdvice" pointcut-ref="serviceAnnotatedClass" order="20" />
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="is*" read-only="true" />
<tx:method name="ownTransaction*" propagation="REQUIRES_NEW" rollback-for="Exception" />
<tx:method name="*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
</beans>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我想出了如何替换aop:pointcut with
<aop:advisor id="managerTx" advice-ref="txAdvice"
pointcut="com.myapp.configuration.AspectConfig.serviceAnnotatedClass()" order="20"/>
Run Code Online (Sandbox Code Playgroud)
和
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class AspectConfig
{
@Pointcut("@within(org.springframework.stereotype.Service)") …Run Code Online (Sandbox Code Playgroud) 有没有办法用特定的jdk启动SonarQube服务器(v.3.7.4)?
我的情况:我的java-home设置为jdk 1.8,但SonarQube服务器有1.8的已知问题.所以我想用jdk 1.7启动服务器(不将我的java-home设置为1.7).我在bat文件中找不到任何东西.
操作系统:Windows 7; SonarQube服务器版本:3.7.4
我很难从OneToMany协会中删除孩子.我的实体:
@Entity
@Table(name = "PERSON")
public class PersonEntity extends BaseVersionEntity<Long> implements Comparable<PersonEntity>
{
...
// bi-directional many-to-one association to Project
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "person", orphanRemoval = true)
private final Set<ProjectEntity> projects = new HashSet<ProjectEntity>();
...
@Entity
@Table(name = "PROJECT")
public class ProjectEntity extends BaseVersionEntity<ProjectPK>
{
@EmbeddedId
private ProjectPK id;
...
// bi-directional many-to-one association to UdbPerson
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PERSON_ID", nullable = false, insertable = false, updatable = false)
private PersonEntity person;
... …Run Code Online (Sandbox Code Playgroud) 此查询用于以一对多关系检索最后的记录(请参阅SQL连接:选择一对多关系中 的最后记录)
SELECT p.*
FROM customer c
INNER JOIN (
SELECT customer_id, MAX(date) MaxDate
FROM purchase
GROUP BY customer_id
) MaxDates ON c.id = MaxDates.customer_id
INNER JOIN purchase p ON MaxDates.customer_id = p.customer_id
AND MaxDates.MaxDate = p.date;
Run Code Online (Sandbox Code Playgroud)
我的问题:如何使用jpa criteria-api的subselect构建此连接?可能吗?如果没有,可以使用jpql吗?
我的代码到目前为止:
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery<Purchase> query = cb.createQuery(Purchase.class);
final Root<CustomerEntity> root = query.from(Customer.class);
// here should come the join with the sub-select
final Path<Purchase> path = root.join(Customer_.purchases);
query.select(path);
final TypedQuery<Purchase> typedQuery = entityManager.createQuery(query);
return typedQuery.getResultList();
Run Code Online (Sandbox Code Playgroud) 我正忙着自己的资源实施.该的getInputStream -方法不会被调用.
我的经纪人:
public class ResourceHandlerWrapperImpl extends
ResourceHandlerWrapper {
private final ResourceHandler wrapped;
public ResourceHandlerWrapper(final ResourceHandler wrapped)
{
this.wrapped = wrapped;
}
@Override
public ResourceHandler getWrapped()
{
return wrapped;
}
@Override
public Resource createResource(final String resourceName, final String libraryName)
{
if (AppConstants.RESOURCE_MEDIA_LIB.equals(libraryName))
{
return new MediaResource(resourceName);
}
else
{
return super.createResource(resourceName, libraryName);
}
}
/**
* @see javax.faces.application.ResourceHandlerWrapper#libraryExists(java.lang.String)
*/
@Override
public boolean libraryExists(final String libraryName)
{
if (AppConstants.RESOURCE_MEDIA_LIB.equals(libraryName))
{
return true;
}
else
{
return super.libraryExists(libraryName);
}
}
/** …Run Code Online (Sandbox Code Playgroud) java ×5
spring ×3
jpa-2.0 ×2
spring-mvc ×2
criteria-api ×1
hibernate ×1
java-8 ×1
java-stream ×1
jax-ws ×1
jsf-2 ×1
mojarra ×1
primefaces ×1
restful-url ×1
sonarqube ×1
web.xml ×1
welcome-file ×1