Spring MVC,JSP页面数字怎么自增,实现排行榜功能序号自增功能
这个不是读写数据库了吗?点红赞的时候后端将对应的数加0,接口返回成功的话前端也加1
不知道你这个问题是否已经解决, 如果还没有解决的话:<form action="/user/fileupload1" method="post" enctype="multipart/form-data">
选择文件:<input type="file" name="upload" /><br/>
<input type="submit" value="上传" />
</form>
可以使用后端控制器(Controller)中的计数器实现自增数字,并传递给对应的JSP页面进行显示。具体步骤如下:
@Controller
public class RankingController {
private static int count = 1;
//其他代码省略
}
@RequestMapping("/rank")
public String rank(Model model) {
model.addAttribute("count", count++);
return "rank";
}
<h3>当前排名:${count}</h3>
这样就实现了在Spring MVC中生成自增数字,用于实现排行榜的功能。不需要使用第三方库或插件。完整代码戳这里:https://github.com/hellokoding/springmvc-series/tree/master/springmvc-pagination-sorting-example