Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以将我的java自动生成id方法转换为Spring Back End_Spring_Spring Boot_Spring Mvc - Fatal编程技术网

是否可以将我的java自动生成id方法转换为Spring Back End

是否可以将我的java自动生成id方法转换为Spring Back End,spring,spring-boot,spring-mvc,Spring,Spring Boot,Spring Mvc,我是春天的新手。我习惯于使用以下方法在java中生成id。 现在我已经在我的spring后端完成了所有其他事情。(如服务层/DAO层) 但是我被困在客户控制器中,因为我不知道如何将这个生成值设置到我的前端 private void generateCourseID() { try { String lastID = courseBO.getCourseID(); int newId = Integer.parseInt(lastID.substring(1

我是春天的新手。我习惯于使用以下方法在java中生成id。 现在我已经在我的spring后端完成了所有其他事情。(如服务层/DAO层) 但是我被困在客户控制器中,因为我不知道如何将这个生成值设置到我的前端

private void generateCourseID() {
    try {
        String lastID = courseBO.getCourseID();
        int newId = Integer.parseInt(lastID.substring(1, 4)) + 1;
        if (newId < 10) {
            txtCourseID.setText("C00" + newId);
        } else if (newId < 100) {
            txtCourseID.setText("C0" + newId);
        } else {
            txtCourseID.setText("C" + newId);
        }


    } catch (Exception e) {
        txtCourseID.setText("C001");
    }
}
private void generateCourseID(){
试一试{
字符串lastID=courseBO.getCourseID();
int newId=Integer.parseInt(lastID.substring(1,4))+1;
if(newId<10){
txtCourseID.setText(“C00”+newId);
}否则如果(新ID<100){
txtCourseID.setText(“C0”+newId);
}否则{
txtCourseID.setText(“C”+newId);
}
}捕获(例外e){
txtCourseID.setText(“C001”);
}
}
我不明白如何在HTML前端设置这个值。 我只想将我的控制器值设置为

如果有人能帮我,我真的很感激。
非常感谢你

请注意,您可以改为使用
String.format(“C%03d”,newId)
。查看另一个堆栈流答案