项目环境
开发系统:win7
开发工具:IDEA
JDK:1.8
框架:Maven+Spring+SpringMVC+Mybatis
数据库:mysql
bean:
package com.demo.bean;
public class OrderType {
private String changeOrderType;
public String getChangeOrderType() {
return changeOrderType;
}
public void setChangeOrderType(String changeOrderType) {
this.changeOrderType = changeOrderType;
}
/* @Override
public String toString(){
return "OrderType{"+ "changeOdersType='"+changeOrderType+"'}";
}*/
}
Dao层接口:
package com.demo.dao;
import com.huawei.promethues.demo.bean.OrderType;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface OrderTypeDao {
public List<OrderType> selectedByOrderType();
}
Service业务层:
package com.demo.service;
import com.demo.bean.OrderType;
import java.util.List;
public interface OrderTypeService {
public List<OrderType> selectedByOrderType();
}
实现Service
package com.demo.service.impl;
import com.demo.bean.OrderType;
import com.demo.dao.OrderTypeDao;
import com.demo.service.OrderTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class OrderTypeServiceImpl implements OrderTypeService{
@Autowired
private OrderTypeDao typeDao;
public List<OrderType> selectedByOrderType(){
return typeDao.selectedByOrderType();
}
}
mapper:
<?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.demo.dao.OrderTypeDao"> <resultMap id="OrderTypeResultMap" type="com.demo.bean.OrderType"> <result column="CHANGE_ORDER_TYPE" property="changeOrderType" jdbcType="VARCHAR"/> </resultMap> <select id="selectedByOrderType" resultMap="OrderTypeResultMap"> SELECT DISTINCT CHANGE_ORDER_TYPE FROM CHANGE_ORDER_DO </select> </mapper>
controller控制器:
package com.demo.console.controller; import com.demo.bean.OrderType; import com.demo.service.OrderTypeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController public class OrderTypeController { @Autowired private OrderTypeService orderTypeService; @RequestMapping(value="orderType") public List<OrderType> findOrderType(){ return orderTypeService.selectedByOrderType(); } }