首页>代码>基于maven与springMVC的拦截器Interceptor,控制器Controller的使用>/Spring-Controller/src/main/java/com/study/controller/TextController.java
package com.study.controller; import java.util.Random; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class TextController { // @RequestMapping("/work") // private ModelAndView workController() { // Random random = new Random(); // int num=random.nextInt(100)%(300-100+1) + 100; // System.out.println("随机数:"+num); // ModelAndView mv =new ModelAndView(); // mv.addObject("info",random); // mv.setViewName("controllerWork"); // return mv; // } @RequestMapping("/work") private String workController(HttpSession session) { Random random = new Random(); //方法一: // int num=(int) (Math.random()*200+100); //方法二: int num=random.nextInt(100)%(300-100+1) + 100; System.out.println("随机数:"+num); session.setAttribute("info", num); return "controllerWork"; } }
最近下载更多
13112360 LV2
2022年9月13日
chenxiufeng LV4
2021年5月1日
g1121345342 LV9
2020年12月16日
walense LV2
2020年3月24日
13940562934 LV22
2019年11月14日
zywzywzyw1 LV17
2019年8月6日
jiajia91323 LV23
2019年4月22日
Friction LV3
2019年4月12日
steelzyoung LV2
2019年2月26日
1194285336 LV1
2019年2月26日