发表于: 2017-05-24 11:05:27

1 1222


今日目标:收尾任务2,完成剩余的接口并且全部使用POSTMAN测试通过。

1.之前接口有些设计不当,思考之后决定删除PATCH操作,删除学员也应该根据自增id精确删除。

2.修改之前的代码,POST操作出现的诡异错误让我意识到单独写Service类并且提交事务、关闭会话的重要性。

3.修改Mapper,删除方法的返回值改为void,Update方法返回值改为int,表示受到影响的自增id数目。

4.发现之前获取单个和多个学生,使用了两个jsp页面,现在统一在服务端跳转到result.jsp,使用EL表达式显示结果。


在增加Service类的时候遇到如下问题:

Controller中:

  1. ……
  2. @Autowired
  3.    StudentService studentService;
  4. ……

Service中:

  1. @Service
  2. public class StudentService {
  3. ……

Tomcat启动时报错。


Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.qhs.rest.service.StudentService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Google出的结果:

在springmvc-servlet.xml中,之前component-scan只扫描了Controller包

将其改为扫描rest包,启动报错解决

  1. <!-- scan the package and the sub package -->
  2. <context:component-scan base-package="com.qhs.rest" />


也让我体会到了IoC的快感,Controller中不必自己new对象了,真正体会到了什么叫低耦合。。


在测试根据id精确获取学员的时候遇到如下问题:

Request processing failed; nested exception is java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/REST/student/43': {public org.springframework.web.servlet.ModelAndView com.qhs.rest.controller.StudentController.getStudentsByName(java.lang.String,java.lang.Integer) throws java.io.IOException, public org.springframework.web.servlet.ModelAndView com.qhs.rest.controller.StudentController.getStudentsById(java.lang.Integer) throws java.io.IOException}

StackOverflow上看到的一个办法是让换一下参数:

https://stackoverflow.com/questions/35155916/handling-ambiguous-handler-methods-mapped-in-rest-application-with-spring


在测试根据id删除学员的时候。。。遇到这个异常

### SQL: delete * from signup where id = ?

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from signup where id = 43' at line 1] with root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from signup where id = 43' at line 1


原来是我的SQL语句写错了……我sql基础还真是差

最后测试根据id修改学员信息的时候……又遇到了异常。。

### SQL: <script> update signupupdate_at = (UNIX_TIMESTAMP(now())*1000<set><if test="name != null">name=?,</if><if test="qq != null">price=?,</if><if test="major != null">price=?,</if><if test="start_date != null">price=?,</if><if test="school != null">price=?,</if><if test="onlineclass != null">price=?,</if><if test="onlineno != null">price=?,</if><if test="diarylink != null">price=?,</if><if test="aim != null">price=?,</if><if test="recommender != null">price=?,</if><if test="censor != null">price=?,</if><if test="wherefrom != null">price=?,</if></set>where id = ?</script>

### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [student, param1]] with root cause

org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [student, param1]

和昨天的一样,需要改成student.属性。

SQL: <script> update signupupdate_at = (UNIX_TIMESTAMP(now())*1000<set><if test="student.name != null">name=?,</if><if test="student.qq != null">qq=?,</if><if test="student.major != null">major=?,</if><if test="student.start_date != null">start_date=?,</if><if test="student.school != null">school=?,</if><if test="student.onlineclass != null">onlineclass=?,</if><if test="student.onlineno != null">onlineno=?,</if><if test="student.diarylink != null">diarylink=?,</if><if test="student.aim != null">aim=?,</if><if test="student.recommender != null">recommender=?,</if><if test="student.censor != null">censor=?,</if><if test="student.wherefrom != null">wherefrom=?,</if></set>where id = ?</script>

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<script> update signupupdate_at = (UNIX_TIMESTAMP(now())*1000<set><if test="stud' at line 1] with root cause


嗨呀 好气呀,这不是意味着我这个动态sql完全没有用么?


先吃个饭,下午再搞

尝试注释掉所有if判断语句,就留一个update_at

### SQL: <script>update `signup` update_at = (UNIX_TIMESTAMP(now())*1000 where id = ?</script>

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<script>update `signup` update_at = (UNIX_TIMESTAMP(now())*1000 where id = 27</s' at line 1] with root cause


别人说能用script标签包裹来实现动态sql都是骗人的哇哇哇


“我认输 我认输.jpg”的图片搜索结果

还是不偷懒了,写一个UpdateProvider吧

http://www.cuiyingfeng.com/pages/viewpage.action?pageId=11370604

参考此文


sql工具类怎么没了……


然后发现我只导入了mybatis-spring,没有mybatis本体。。

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= (UNIX_TIMESTAMP(now())*1000 SET name='韩立',qq='12345566',major='JAVA工程' at line 1

这回倒是能拿到数据了。。也不用写这个provider了。。基本确定是sql语句的问题。。


把生成的sql语句拿到MySQL-Front里去调试。。


原来是某些细节问题。。多了一个左括号和一个逗号。。

至此,任务2全面完成。

验收结果:

增:

删:

改:

查:

精确:

根据姓名批量查询:

根据专业批量查询:

分页查询(可以与major、name混合使用):

深度思考:

1.什么是restful?

一种设计风格,采用json格式传输数据,用HTTP方法表明要做什么,URL使用简洁的静态名词,不要出现add等动词。

2.了解maven的module。


阅读了这篇文章:http://juvenshun.iteye.com/blog/305865,但是没有实际开发过这种复杂度的项目,缺乏实际理解。

3.rest的请求方法有哪些,有什么区别?

post:用于新增,put:用于修改,get:用于获取,delete:用于删除

4.什么是http协议?Get和post请求有什么区别?http请求content-Type有几种,有什么区别?http请求的三次握手具体指什么?http适合什么场景?什么是tcp/ip协议?http状态码有哪些?

http:超文本传输协议


get和post的区别:post隐式提交表单或者其他数据,get则把参数放在地址栏里,安全性较差


content-Type:用过的有text/html,用于传输html网页,以及application/json,用于传输json数据。

听说过的有application/xml,image/jpeg。具体参见http://tool.oschina.net/commons。


http三次握手:

客户端问服务端:喂,听得到吗,然后开始等待服务端回复(进入SYN_SENT状态);

服务端听到之后说:我听得到,你听得到吗(服务器进入SYN_RECV状态)

客户端听到之后说:我也听得到(客户端和服务器进入ESTABLISHED状态)


http适用什么场景?

。。这个不太好回答……?

网页传输,前后端交互,大部分都是HTTP吧?


TCP/IP协议是什么?

TCP协议是一种可靠的,需要持续连接的通信协议,IP协议则定义了数据包和网络地址,但自身并不负责维护数据包的稳定性,只负责通往这个地址路上的路由等等。。


HTTP状态码:

常用的有404资源找不到,403访问被拒绝,401需要认证,500服务器出错,415传输数据格式不匹配,200ok。。记得看到过一篇用状态码写的小黄文(。






返回列表 返回列表
评论

    分享到