小编Gri*_*Dog的帖子

如何将bean注入@Controller类

我对Spring(使用3.0)有些新意,所以我希望有一个简单的答案.如果我有一个带有@Controller和的注释控制器,@RequestMapping并且我想通过依赖注入设置属性,我该如何去做呢?控制器类不必出现在Spring配置文件中,因为它会因@Controller注释而自动拾取.

示例控制器类:

package gov.wi.dnr.wh.web.spring;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class RehabHomeController {
  private String xxx;

  @RequestMapping(value="/rehab/home", method = RequestMethod.GET)
  public String get() {
    return "whdb.rehabhome";
  }

  public String getXxx() {
    return xxx;
  }

  public void setXxx(String xxx) {
    this.xxx = xxx;
  }
}
Run Code Online (Sandbox Code Playgroud)

弹簧配置:

<?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:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
                            http://www.springframework.org/schema/context 
                      http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
  </bean> …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

20
推荐指数
1
解决办法
2万
查看次数

Spring @Transactional边界

我在服务层使用@Transactional.如果我使用@Transactional注释两个更新服务方法(使用默认设置)并且控制器方法正在调用这两个方法来执行其操作,那么两个服务方法是否都使用相同的事务?

似乎他们没有,我正在寻找对此的确认.在我看来,为了让两个方法都使用相同的事务,我需要在服务中编写第三个方法,用@Transactional注释它,然后从那里调用原来的两个方法.

java spring

11
推荐指数
1
解决办法
1717
查看次数

Oracle嵌套相关子查询问题

考虑table1和table2具有一对多关系(table1是主表,table2是详细信息表).我想从table1获取记录,其中某些值('XXX')是与table1相关的详细记录的table2中最新记录的值.我想要做的是:

select t1.pk_id
  from table1 t1
 where 'XXX' = (select a_col
                  from (  select a_col
                            from table2 t2
                           where t2.fk_id = t1.pk_id
                        order by t2.date_col desc)
                 where rownum = 1)
Run Code Online (Sandbox Code Playgroud)

但是,因为相关子查询中对table1(t1)的引用是两级深度,所以它会弹出Oracle错误(无效的id t1).我需要能够重写这个,但有一点需要注意,只有where子句可以改变(即初始select和from必须保持不变).可以吗?

sql oracle

5
推荐指数
1
解决办法
5819
查看次数

通过充气城堡库将der转换为pem

我发现了许多将pem转换为der的答案。

但是,我找不到将der转换为pem的方法

例如,以下代码生成der编码文件pkcs10.cer

public static void main(String[] args) throws Exception
{
    X509Certificate[] chain = buildChain();
    PEMWriter pemWrt = new PEMWriter(new OutputStreamWriter(System.out));
    pemWrt.writeObject(chain[0]);

    FileWriter fwO = new FileWriter("pkcs10.cer");
    fwO.write((chain[0]).toString());

    fwO.close();
    pemWrt.close();

}
Run Code Online (Sandbox Code Playgroud)

像[0]版本:3序列号:1353995641265 IssuerDN:CN = Test证书开始日期:2012年11月26日星期一21:54:01最终日期:2012年11月26日星期一21:54:51

但是,我不知道如何从der文件中进行pem编码的认证。

java cryptography bouncycastle x509

0
推荐指数
1
解决办法
6050
查看次数

标签 统计

java ×3

spring ×2

bouncycastle ×1

cryptography ×1

oracle ×1

spring-mvc ×1

sql ×1

x509 ×1