我查看了许多Spring和Hibernate技巧,并没有找到"教程"形式的实际示例.通过现实世界我的意思是(例如):
指出上述三个例子的指针将不胜感激.
我正在尝试编写一个程序,它会一直询问用户一个整数,直到他们输入一个非整数的值,此时程序停止.
这是我到目前为止:
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) 我正在使用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
"Java 8 Lambdas:实用功能编程"有一个peek在StreamAPI中使用方法的例子.这段代码打印名称以"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"))?
我想知道我将如何添加一个JPanel到JFrame,并确保它是中心,并有一组大小对两侧的空隙?我可以在中心得到它,但它坚持边缘.
我在春季批次中有自己的 fieldsetmapper。我想跳过一些符合某些标准的行。如果我在 mapFieldSet(FieldSet fieldSet) 中返回 null,itemreader 将停止。这意味着不会处理剩余的行。
那么如何跳过 mapFieldSet 中的行呢?
我正在使用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) 您好,我正在尝试使用 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) 我试图从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) 好吧基本上我正在尝试编写一个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 ×9
spring ×3
hibernate ×2
swing ×2
colors ×1
graphics ×1
java-8 ×1
java-io ×1
lambda ×1
rmi ×1
spring-batch ×1
spring-data ×1
spring-jdbc ×1
spring-mvc ×1
sql ×1