为什么我的mybatis查询为null?
这是我的SQL语句
然后就是我的xml文件__
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.experience.dao.User_orders_dao">
<select id="getOrders" resultMap="Orders">
select * from orders where
orders.id = #{id};
</select>
<resultMap id="Orders" type="com.experience.entity.User">
<id property="id" column="id"/>
<result property="username" column="username"/>
<result property="password" column="password"/>
<result property="sex" column="sex"/>
<result property="tel" column="tel"/>
<result property="address" column="address"/>
<collection property="orders" ofType="com.experience.entity.Orders">
<id property="id" column="id"/>
<result property="goodsname" column="goodsname"/>
<result property="time" column="time"/>
</collection>
</resultMap>
</mapper>
我的实体类
package com.experience.entity;
import java.util.List;
public class User {
private int id;
private String username;
private String password;
private String sex;
private String tel;
private String address;
private List<Orders> orders;
public List<Orders> getOrders() {
return orders;
}
public void setOrders(List<Orders> orders) {
this.orders = orders;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", password='" + password + '\'' +
", sex='" + sex + '\'' +
", tel='" + tel + '\'' +
", address='" + address + '\'' +
'}';
}
}
实体类
package com.experience.entity;
public class Orders {
private int id;
private String goodsname;
private String time;
public long getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGoodsname() {
return goodsname;
}
public void setGoodsname(String goodsname) {
this.goodsname = goodsname;
}
public String getTime() {
return time;
}
public void setTime() {
this.time = time;
}
@Override
public String toString() {
return "Orders{" +
"id=" + id +
", goodsname='" + goodsname + '\'' +
", time=" + time +
'}';
}
}
dao层
package com.experience.dao;
import com.experience.entity.Orders;
import com.experience.entity.User;
import java.util.List;
public interface User_orders_dao {
List<User> getOrders(int id);
}
service层
package com.experience.service.impl;
import com.experience.dao.User_orders_dao;
import com.experience.entity.User;
import com.experience.service.User_orders_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class User_orders_service_impl implements User_orders_service {
@Autowired
User_orders_dao user_orders_dao;
@Override
public List<User> getOrders(int id) {
return user_orders_dao.getOrders(id);
}
}
Controller层
package com.experience.controller;
import com.experience.entity.Orders;
import com.experience.entity.User;
import com.experience.service.User_orders_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
public class User_orders_Controller {
@Autowired
User_orders_service user_orders_service;
@RequestMapping("/getList")
public void getList(@RequestParam(value = "id",required = true) int id){
List<User> orders = user_orders_service.getOrders(id);
orders.stream().forEach(obj -> System.out.println(obj));
}
}
输出结果