发表于: 2017-09-28 22:09:48
3 781
一、今日完成
1.修改任务4代码,部署到线上服务器,然后提交成果
(1)问题1
在mapper.xml的SQL语句里,出现语法错误
<update id="updateStudentById" parameterType="com.task.onca.domain.Student">
UPDATE student
SET stu_name=#{Student.stu_name},stu_pwd=#{Student.stu_pwd},stu_QQ=#{Student.stu_QQ}, category=#{Student.category}, admission_date=#{Student.admission_date}, institution=#{Student.institution},
online_number=#{Student.online_num}, daily_link=#{Student.daily_link}, oath=#{Student.oath}, tutor=#{Student.tutor}, auditor=#{Student.auditor},update_at=#{Student.update_at},TEL=#{Student.TEL},company=#{Student.company}, position=#{Student.position}, summary=#{Student.summary}
WHERE id=#{Student.id}
</update>
因为student表字段较多,输入字段名过程中,把部分单词写错,导致控制台有输出MySQL语法错误的信息;
(2)问题2
在home.jsp courselist.jsp等页面里把跳转页面的相对路径修改成“/projectname/viewname”
<li><a href="/onca/courselist">职业</a></li>
<a href="/onca/home"><li>首 页</li></a>
2,在本地执行mvn clean install命令生成war包,上传到服务器里tomcat的webaaps目录下,再执行任务3中编写的war包部署和运行脚本,通过“服务器公网IP+端口号+viewname”就可以再客户端浏览器上访问相应页面
2.总结整理Spring MVC常用的一些注解
(1)@Controller
@Controller用于标记一个类,声明该类是一个Spring MVC Controller对象,在Controller类中,使用了@RequestMapping注解的方法时真正处理请求的处理器。为了保证Spring找到控制器,必须配置如下两处:
1)在Spring MVC配置文件里引入spring-context
2)使用<context:component-scan/>元素,启动包扫描功能,以便将带有@controller @Service @repository @Component等注解的类变成Spring的bean。
@Controller
public class HelloWorldController{
@RequestMapping("/helloWorld")
public String helloWorld(Model model) {
model.addAttribute("message", "Hello World!");
return "helloWorld";
}
}
HelloWorldController是一个基于@Controller注解的控制器,@RequestMapping注解用来映射一个请求,value=‘//helloWorld’表示请求由helloWorld方法进行处理。helloWorld方法接收一个Model类型的参数,在model中添加了一个名称为“message”的字符串对象,在返回的视图中通过request对象获取。最终方法返回值“helloWorld”,这是视图名称,即对应的JSP文件名。
(2)@RequestMapping
@Controller
// RequestMapping可以用来注释一个控制器类,此时,所有方法都将映射为相对于类级别的请求,
// 表示该控制器处理所有的请求都被映射到 value属性所指示的路径下
@RequestMapping(value="/user")public class UserController{
}
// 该方法映射的请求为http://localhost:8080/context/user/register,该方法支持GET请求
@RequestMapping(value="/register",method=RequestMethod.GET)
public String registerForm() {
logger.info("register GET方法被调用...");
// 跳转到注册页面
return "registerForm";
}
@RequestMapping可以用来注释一个控制器类,通过设置value属性,表示该处理器处理的所有请求都被映射到value属性所声明的路径下,即所有与UserController类相关的路径都要加上/user
@RequestMapping也可以用来注释控制器的方法,除了value属性外,设置method属性指示该方法仅仅处理哪些HTTP请求,即使客户端发送的URL相同但是请求方法与method属性不一致,控制器也不会调用该方法。
method可以设置相应多个请求,或者不指定method表示该方法可以处理任何HTTP请求。
(3)在处理请求方法可出现和返回的参数类型中,使用Model和ModelAndView对象实现将模型数据传递给视图。
其用法分别是:
addObject(String attributeName, Object attributeValue);
addObject(String attributeName, Object attributeValue);
而且ModelAndView对象还提供了设置view的方法
setViewName(String viewName);
(4)其他一些参数绑定用到的注解@RequestParam @RequestMapping @PathVariable @RequestHeader @SessionAttibute @ModelAttribute等用法相对简单,不在这里说明了。
二、明日计划
1.学习Spring MVC实现数据转换用到的注解;
2.开始做任务5.
三、遇到问题
无。
四、收获
以上。
禅道:http://task.ptteng.com/zentao/task-view-10369.html
任务四已经完成。
评论