==>  Preparing: select * from t_user where password= '12345' 
==> Parameters: 
<==    Columns: id, name, password
<==        Row: 5, admin, 12345
<==      Total: 1
==>  Preparing: select * from t_user where password= '12345' 
==> Parameters: 
<==    Columns: id, name, password
<==        Row: 5, admin, 12345
<==      Total: 1

 

1、使用postman 进行绑定数据的url 请求时候, 一直无法接受到数据

         http://localhost:8080/user?i =1

  发现上面 i 后面有个空格

去除空格之后, 就可以接受数据

 

2、 执行sql 语句中报错显示列名无效

SELECT  *  FROM  t_user  WHERE   password = "12345"

 应该是改成 

SELECT  *  FROM  t_user  WHERE   password = '12345'

 

3、  数据库查询过程的中坑, #, $ 的使用问题

sql: 

   select *
from t_user
where
password= #{password}
url: http://localhost:8080/user?name='admin'&password='12345'
==> Preparing: select * from t_user where password= ? ==> Parameters: '12345'(String) <== Total: 0
url: http://localhost:8080/user?name="admin"&password="12345"
==>  Preparing: select * from t_user where password= ? 
==> Parameters: "12345"(String)
<==      Total: 0

sql: 

   select *
from t_user
where
password= ${password}
url: http://localhost:8080/user?name="admin"&password="12345"
SQL: select *         from t_user         where         password= "12345"
Cause: com.microsoft.sqlserver.jdbc.SQLServerException: 列名 '12345' 无效。

 

url: http://localhost:8080/user?name='admin'&password='12345'
==>  Preparing: select * from t_user where password= '12345' 
==> Parameters: 
<==    Columns: id, name, password
<==        Row: 5, admin, 12345
<==      Total: 1
总结:  前端传递字符串的时候,应该是' ', 后端使用${}


4 前端传送json 数据, 后端接收问题

 

 

    @ResponseBody
    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public User queryUser(@RequestBody User user){
        System.out.println("-------- 接收数据 --------");
        System.out.println(user.getName());
        System.out.println(user.getPassword());
        User user1 = userMapper.queryUser(user);
        return user1;
    }
原来没有上面 @RequestBody的时候, 无法接受数据,显示为null, 现在加上这个注解之后,显示没有问题
问题: 原来发送数据的时候, 没有加@RequestBody 的时候, 也可以接受数据

@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,比如说:application/json或者是application/xml等。一般情况下来说常用其来处理application/json类型

@requestBody可以将请求体中的JSON字符串绑定到相应的bean上

https://blog.csdn.net/itjauser/article/details/90514754

 

5、 数据库查询多条数据的时候,返回的类型不是一个集合,而是这个单个类型的数据类型

before:

    <select id = "getItemsList" resultType="List">
        select * from t_items
    </select>

返回的json 数据是为空的 “[ ] ”

after:

    <select id = "getItemsList" resultType="com.wchat.secondhand.entity.Items">
        select * from t_items
    </select>

返回的 list 集合。

 

 

6、后端接收参数的问题, 关于  @RequestParam(value = "file") 的使用

public boolean upLoadItems(@RequestParam(value = "items) Items items, @RequestParam(value = "file") MultipartFile file){}

向上面这种,使用注解修饰, 只能接收到 两个前端传入的的两个参数

 

public boolean upLoadItems(Items items, @RequestParam(value = "file") MultipartFile file){}

上面参数中可以接收items 里面的所有属性, 以及file 属性

 

7、 select  *  from  使用会造成数据查询丢失问题
在项目中使用 select * from 发现一个字段查出来显示为空,但是自己去数据库
查看发现是有数据的,所以出现了数据丢问题,所以使用select 字段1, 字段2 from t_table 这种形式
进行数据的查询
 





posted on 2020-01-07 08:51  黄山一叶  阅读(183)  评论(0编辑  收藏  举报