发表于: 2017-07-25 23:44:12
3 1177
今天完成的事情:
3. @PathVariable 用法
明天计划的事情:
1. 学习JSP
2. 能成功在网页里显示查询到的信息
3. 学习web.xml文件
4. 学习spring-mvc.xml文件
5. 学习各种注解的作用
遇到的问题:
1. 网页不能传递参数,没有标注@Autowired
@Autowired
private StudentService studyService;
计划明天好好学习注解的作用
收获:
方法一:
@RequestMapping(value="/a/student/detail",method = RequestMethod.GET)
public String detail(HttpServletRequest request, HttpServletResponse response, Model model) {
try {
logger.info("这是学生详细信息的查询");
String user_id = request.getParameter("user_id");
logger.info(user_id);
StudentMod study = this.studyService.getUserId(user_id);
logger.info(study);
model.addAttribute("study",study);
访问方式:http://localhost:8081/task2/a/student/detail?user_id=JAVA-1111
方法二:
@RequestMapping(value="/a/student/detail/{user_id}",method = RequestMethod.GET)
public String detail(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable String user_id) {
try {
logger.info("这是学生详细信息的查询");
logger.info(user_id);
StudentMod study = this.studyService.getUserId(user_id);
logger.info(study);
model.addAttribute("study",study);
访问方式:http://localhost:8081/task2/a/student/detail/JAVA-1111
method表示对资源进行的操作
GET表示获取资源
POST表示更新添加资源
PUT表示修改资源
DELETE表示删除资源
服务层接口
public interface StudentService {
StudentMod getUserId(String user_id);
}
实现:
@Service("userService")
public class StudentServiceImpl implements StudentService{
@Resource
private StudentMapper studyDao;
public StudentMod getUserId(String user_id){
return this.studyDao.studySelect(user_id);
}
}
3. @PathVariable 用法
@PathVariable
使用@PathVariable时,URL是这样的:http://host:port/path/参数值
参考资料:
评论