小编che*_*atu的帖子

如何在弹簧靴中设置过滤链?

我遇到了spring-boot,并打算为传入请求添加一个过滤器链.

这是应用程序:

package example.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(Application.class, args);
    }

}
Run Code Online (Sandbox Code Playgroud)

这是控制器:

package example.hello;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        return new Greeting(counter.incrementAndGet(),
                String.format(template, name));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是过滤器配置:

package example.hello;

import org.springframework.boot.context.embedded.FilterRegistrationBean;
import …
Run Code Online (Sandbox Code Playgroud)

java spring servlet-filters spring-boot

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

这些java本机内存是从哪里分配的?

JDK版本是热点8u_45

我研究了我的 java 进程的本机内存。本机内存甚至比堆消耗更多的空间。然而,有许多本机内存块让我感到困惑。例如 pmap -x 的结果:

00007f8128000000   65508   25204   25204 rw---    [ anon ]
00007f812bff9000      28       0       0 -----    [ anon ]
00007f812c000000   65508   24768   24768 rw---    [ anon ]
00007f812fff9000      28       0       0 -----    [ anon ]
00007f8130000000   65508   25532   25532 rw---    [ anon ]
00007f8133ff9000      28       0       0 -----    [ anon ]
00007f8134000000   65524   22764   22764 rw---    [ anon ]
00007f8137ffd000      12       0       0 -----    [ anon ]
00007f8138000000   65508   26456   26456 rw---    [ anon ]
00007f813bff9000 …
Run Code Online (Sandbox Code Playgroud)

java memory java-native-interface jvm pmap

8
推荐指数
1
解决办法
1384
查看次数

直接有效地读写硬盘扇区

我特别需要块数据存储.我的数据是格式化的数据块,大小为4096.为了高效率,我想直接操作硬盘扇区上的块,并且不希望将数据块视为文件.我认为一种方法是将设备视为文件,例如/ dev/sda1,并使用lseek()read()和write()来读取和写入数据.但是我不知道文件头是否是硬盘的第一个扇区.我也怀疑这种方法的效率.

我正在研究Linux OS和C编程语言.

处理硬盘扇区最有效的方法是什么?我应该写一个linux的块设备模块.但是,我对此并不了解.我应该使用哪些内核函数来读取和写入块设备?

c linux linux-kernel hard-drive

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

JDBC mysql不支持PreparedStatement中LIMIT的占位符?

我使用mysql-connector-java-5.1.38在Windows 10 64位上运行mysql-community-5.7.10.0.

我尝试将值绑定limit为分页

"SELECT * FROM employee LIMIT ?, ?"
Run Code Online (Sandbox Code Playgroud)

但结果显示:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?, ?' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1370)
    at SqlTest.main(SqlTest.java:65)
Run Code Online (Sandbox Code Playgroud)

但是,我直接尝试了navicat中的sql,但可以得到正确的答案: …

java mysql jdbc prepared-statement

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