小编Ash*_*yan的帖子

是否有真实的Spring和Hibernate示例的来源?

我查看了许多Spring和Hibernate技巧,并没有找到"教程"形式的实际示例.通过现实世界我的意思是(例如):

  1. 搜索用于检索Person对象.然后显示该对象细节.然后,用户修改对象的字段,并提交表单并保存对象.大多数示例以相同的方法执行检索和保存,这与Spring网站上的示例相同.
  2. 一个对象有超过3或4个字段,包括通常不在表单上的字段(例如createdDate,createdBy,lastModifiedDate,lastModifiedBy).
  3. 命令对象与表单相关联.所以我们有person.jsp,PersonForm.java和PersonController.java.

指出上述三个例子的指针将不胜感激.

java spring hibernate

4
推荐指数
1
解决办法
2926
查看次数

要求用户进行多次输入

我正在尝试编写一个程序,它会一直询问用户一个整数,直到他们输入一个非整数的值,此时程序停止.

这是我到目前为止:

import java.util.Scanner;
import java.util.ArrayList;

public class InputStats {
    private static Scanner a;

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        ArrayList InputArray = new ArrayList();
        Boolean Running = true;
        System.out.println("Please type an integer. To stop enter a non integer value");
        while (Running) {
            a = Scanner.nextLine();
            if (!a.hasNextInt()) {
                Running = false;
            }
            else {
                InputArray.add(input.nextLine());

        }

            System.out.println(InputArray);
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,使用此代码我收到错误:

error: non-static method nextLine() cannot  be referenced from a static context (for the …
Run Code Online (Sandbox Code Playgroud)

java java-io

3
推荐指数
1
解决办法
152
查看次数

Spring 4 + Hibernate 4 IllegalArgumentException:属性'sessionFactory'是必需的

我正在使用Spring Data和Hibernate编写DAL但是我遇到了一个IllegalArgumentException异常,它阻止了我的工作.

这是DALConf.java包含DataSource和持久性异常转换处理器配置的类

package my.dal.config;

import java.util.Properties;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;


@Configuration
@ComponentScan(basePackages = { "my.dal" })
@PropertySource("classpath:dbconnection.properties")
public class DALConfig {

    private static final String PROPERTY_NAME_DATABASE_DRIVER = "db.driver";  
    private static final String PROPERTY_NAME_DATABASE_PASSWORD = "db.password";  
    private static final String PROPERTY_NAME_DATABASE_URL = "db.url";  
    private static final String PROPERTY_NAME_DATABASE_USERNAME = "db.username";  
    private static final String PROPERTY_NAME_POOL_INITIAL_SIZE = "pool.initialsize";
    private static final String PROPERTY_NAME_POOL_MAX_IDLE …
Run Code Online (Sandbox Code Playgroud)

java hibernate sessionfactory illegalargumentexception spring-data

3
推荐指数
1
解决办法
6296
查看次数

使用方法引用替换链式方法调用

"Java 8 Lambdas:实用功能编程"有一个peekStreamAPI中使用方法的例子.这段代码打印名称以"The"开头的艺术家国籍:

Set<Nationality> nationalities = album.getMusician()
                                 .filter(artist -> artist.getName().startsWith("The"))
                                 .map(artist -> artist.getNationality())
                                 .peek(nation -> System.out.println(nation))
                                 .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

我想用方法引用重写此代码:

Set<Nationality> nationalities = album.getMusician()
                                 .filter(artist -> artist.getName().startsWith("The"))
                                 .map(Artist::getNationality)
                                 .peek(System.out::println)
                                 .collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)

有没有重写的解决方案filter(artist -> artist.getName().startsWith("The"))

java lambda java-8

3
推荐指数
1
解决办法
1878
查看次数

JFrame和JPanel居中

我想知道我将如何添加一个JPanelJFrame,并确保它是中心,并有一组大小对两侧的空隙?我可以在中心得到它,但它坚持边缘.

java swing

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

如何跳过当前字段集并在春季批次中继续下一个

我在春季批次中有自己的 fieldsetmapper。我想跳过一些符合某些标准的行。如果我在 mapFieldSet(FieldSet fieldSet) 中返回 null,itemreader 将停止。这意味着不会处理剩余的行。

那么如何跳过 mapFieldSet 中的行呢?

spring spring-batch

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

Spring Security 3.2.1具有不同WebSecurityConfigurerAdapters的多个登录表单

我正在使用Spring Security 3.2.1.RELEASE和Spring MVC 4.0.4.RELEASE

我正在尝试为具有两个不同登录条目页面的Web应用程序设置Spring Security.我需要将页面区分开来,因为它们的样式和访问方式不同.

首次登录页面适用于管理员用户并保护管理员页面/ admin/**

第二个登录页面适用于客户用户并保护客户页面/客户/**.

我试图设置两个WebSecurityConfigurerAdapter子类来配置各个HttpSecurity对象.

CustomerFormLoginWebSecurity正在保护客户页面,如果未经授权,则会重定向到客户登录页面.如果未经授权,AdminFormLoginWebSecurity正在保护管理页面重定向到管理员登录页面.

不幸的是,似乎只强制执行第一个配置.我认为我错过了一些额外的东西来使这两者都起作用.

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Autowired
    public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser("customer").password("password").roles("CUSTOMER").and()
                .withUser("admin").password("password").roles("ADMIN");
    }

    @Configuration
    @Order(1)
    public static class CustomerFormLoginWebSecurity extends WebSecurityConfigurerAdapter {

        @Override
        public void configure(WebSecurity web) throws Exception {
            web
                    .ignoring()
                    .antMatchers("/", "/signin/**", "/error/**", "/templates/**", "/resources/**", "/webjars/**");
        }

        protected void configure(HttpSecurity http) throws Exception {
            http
                    .csrf().disable()
                    .authorizeRequests()
                    .antMatchers("/customer/**").hasRole("CUSTOMER")
                    .and()
                    .formLogin()
                    .loginPage("/customer_signin")
                    .failureUrl("/customer_signin?error=1")
                    .defaultSuccessUrl("/customer/home")
                    .loginProcessingUrl("/j_spring_security_check")
                    .usernameParameter("j_username").passwordParameter("j_password")
                    .and()
                    .logout()
                    .permitAll();

            http.exceptionHandling().accessDeniedPage("/customer_signin"); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

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

springframework.jdbc.UncategorizedSQLException:无效的列类型-

您好,我正在尝试使用 spring jbdc 执行 QueryForInt。查询返回一个简单的计数。执行时我得到 springframework.jdbc.UncategorizedSQLException:java.sql.SQLException: 无效的列类型。我确实找到了类似的帖子并尝试了建议,但我仍然陷入困境:(...任何帮助表示赞赏。

MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue(DAOConstants.PROD_ID, custVo.getProdId(),OracleTypes.NUMBER);
    params.addValue(DAOConstants.REQ_IND,  DAOConstants.FLAG_Y,OracleTypes.VARCHAR);
Run Code Online (Sandbox Code Playgroud)

查询:

  select count(1) from prod where prod_id = :PROD_ID and req_ind =:REQ_IND
Run Code Online (Sandbox Code Playgroud)

表定义

   Name              Null     Type         
   ----------------- -------- ------------ 
   PROD_ID           NOT NULL NUMBER(5)          
   REQ_IND                    VARCHAR2(10) 
Run Code Online (Sandbox Code Playgroud)

日志..

  Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; 
uncategorized SQLException for SQL [select count(1) from prod where prod_id = :PROD_ID and req_ind = :REQ_IND ]; SQL state [99999]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
    at …
Run Code Online (Sandbox Code Playgroud)

java sql spring-jdbc

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

RMI没有这样的对象异常

我试图从Oracle页面运行Hello World RMI示例,但我一直在收到错误.

我一直得到的错误是

服务器异常:java.rmi.NoSuchObjectException:表java.rmi.NoSuchObjectException中没有这样的对象:在sun.rmi.transport.StreamRemoteCall的sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275)中的表中没有这样的对象.executeCall(StreamRemoteCall.java:252)at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:378)at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)at example.hello.Server.main(Server的.java:26)

以下是直接从我使用的网站获取的代码:

Hello接口:

package example.hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
    String sayHello() throws RemoteException;
}
Run Code Online (Sandbox Code Playgroud)

这是我的服务器类:

package example.hello;

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class Server implements Hello {

    public Server() {}

    public String sayHello() {
        return "Hello, world!";
    }

    public static void main(String args[]) {

    try {
        Server obj = new Server();
        Hello stub = (Hello) UnicastRemoteObject.exportObject(obj,0);

        // Bind the remote object's stub …
Run Code Online (Sandbox Code Playgroud)

java rmi

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

Java Graphics,使用click事件更改图形的颜色

好吧基本上我正在尝试编写一个GUI应用程序,在其主窗口中绘制2个圆圈和2个矩形.我试图得到它,以便每当用户在圆圈或矩形内点击时,该特定圆或矩形变为另一种随机颜色.

目前我已经得到它,以便MouseClick事件(屏幕上的任何地方)导致所有的圆形或矩形将颜色改变为相同的颜色.这是我到目前为止所得到的:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;


public class Question2 {
    public static void main(String[] args) {
        SecondFrame f = new SecondFrame("Draw and Fill");
        f.init();
    }
}   

class SecondFrame extends JFrame{
    SecondFrame(String title) {
        super(title);
    }   

    private JPanel mainPanel;
    private GridBagConstraints gbc = new GridBagConstraints();
    private GridBagLayout gbLayout = new GridBagLayout();

    void init() {
        mainPanel = new JPanel();
        mainPanel.setLayout(gbLayout);
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setContentPane(mainPanel);
        gbc.gridheight = …
Run Code Online (Sandbox Code Playgroud)

java graphics swing colors mouseclick-event

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