提交 2b255ccc 编写于 作者: U u014427391

获取商品品类信息,fix bug#mybatis错误:Invalid bound statement (not found),原因是mybatis的xml配置namespace写错了,注意!

上级 aaeeb66b
package com.muses.taoshop.common.core.database.annotation;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Component;
import java.lang.annotation.*;
......@@ -21,6 +22,7 @@ import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Component
@Mapper
public @interface MybatisRepository {
String value() default "";
}
package com.muses.taoshop.web.controller;
import org.apache.log4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <pre>
* TODO 类说明
* </pre>
*
* @author nicky
* @version 1.00.00
* <pre>
* 修改记录
* 修改后版本: 修改人: 修改日期: 2018.06.18 00:12 修改内容:
* </pre>
*/
public class BaseController {
public Logger log = null;
/**
* 获取日志对象
* @return
*/
public Logger getInstance(){
if(log == null){
log = (Logger) LoggerFactory.getLogger(BaseController.class);
}
return log;
}
}
......@@ -3,8 +3,10 @@ package com.muses.taoshop.web.controller.portal;
import com.alibaba.fastjson.JSON;
import com.muses.taoshop.item.entity.ItemBrand;
import com.muses.taoshop.item.entity.ItemCategory;
import com.muses.taoshop.item.entity.dto.ItemCategoryDTO;
import com.muses.taoshop.item.service.IItemBrankService;
import com.muses.taoshop.item.service.IItemCategoryService;
import com.muses.taoshop.web.controller.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -29,7 +31,7 @@ import java.util.List;
*/
@Controller
@RequestMapping("/portal")
public class IndexController {
public class IndexController extends BaseController{
@Autowired
IItemBrankService iItemBrankService;
......@@ -49,7 +51,7 @@ public class IndexController {
@GetMapping(value = "/doTest")
@ResponseBody
public String doTest(){
public String doTest(){
List<ItemBrand> itemBrands = iItemBrankService.listItemBrand();
String str = JSON.toJSON(itemBrands).toString();
return str;
......@@ -58,11 +60,12 @@ public class IndexController {
@GetMapping(value = "/listRootCategory")
@ResponseBody
public String listRootCategory(){
List<ItemCategory> categories = new ArrayList<ItemCategory>();
List<ItemCategoryDTO> categories = new ArrayList<ItemCategoryDTO>();
categories = iItemCategoryService.listCategory();
String jsonString = "";
if(!CollectionUtils.isEmpty(categories)){
jsonString = JSON.toJSON(categories).toString();
//log.debug("商品品类信息json数据:"+jsonString);
return jsonString;
}
return jsonString;
......
......@@ -3,7 +3,7 @@ server:
logging:
config: classpath:logback.xml
level:
com.muses.taoshop.item.mapper: debug
com.muses.taoshop.*.mapper: trace
spring:
datasource:
......
package com.muses.taoshop.item.entity.dto;
import com.muses.taoshop.item.entity.ItemCategory;
import java.util.Date;
import java.util.List;
/**
* <pre>
* 商品品类
* </pre>
* @author nicky
* @version 1.00.00
* <pre>
* 修改记录
* 修改后版本: 修改人: 修改日期: 2018.06.09 21:49 修改内容:
* </pre>
*/
public class ItemCategoryDTO {
/**
* 商品品类id
*/
private Long id;
/**
* 商品品类名称
*/
private String categoryName;
/**
* 上级id
*/
private Long sjid;
/**
* 上次修改时间
*/
private Date lastModifyTime;
/**
* 创建时间
*/
private Date createTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName == null ? null : categoryName.trim();
}
public Long getSjid() {
return sjid;
}
public void setSjid(Long sjid) {
this.sjid = sjid;
}
public Date getLastModifyTime() {
return lastModifyTime;
}
public void setLastModifyTime(Date lastModifyTime) {
this.lastModifyTime = lastModifyTime;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
package com.muses.taoshop.item.entity.vo;
/**
* <pre>
* TODO 类说明
* </pre>
*
* @author nicky
* @version 1.00.00
* <pre>
* 修改记录
* 修改后版本: 修改人: 修改日期: 2018.06.18 00:06 修改内容:
* </pre>
*/
public class ItemCategoryVO {
}
package com.muses.taoshop.item.service;
import com.muses.taoshop.item.entity.ItemCategory;
import com.muses.taoshop.item.entity.dto.ItemCategoryDTO;
import java.util.List;
......@@ -21,5 +22,5 @@ public interface IItemCategoryService {
* 查询根级商品品类信息
* @return
*/
List<ItemCategory> listCategory();
List<ItemCategoryDTO> listCategory();
}
......@@ -27,6 +27,15 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- 设置源文件编译 -->
<plugin>
......
......@@ -2,12 +2,13 @@ package com.muses.taoshop.item.mapper;
import com.muses.taoshop.common.core.database.annotation.MybatisRepository;
import com.muses.taoshop.item.entity.ItemCategory;
import com.muses.taoshop.item.entity.dto.ItemCategoryDTO;
import java.util.List;
@MybatisRepository
public interface ItemCategoryMapper {
List<ItemCategory> listRootCategory();
List<ItemCategoryDTO> listRootCategory();
}
\ No newline at end of file
package com.muses.taoshop.item.service;
import com.muses.taoshop.item.entity.ItemCategory;
import com.muses.taoshop.item.entity.dto.ItemCategoryDTO;
import com.muses.taoshop.item.mapper.ItemCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -31,7 +32,7 @@ public class ItemCategoryServiceImpl implements IItemCategoryService{
* @return
*/
@Override
public List<ItemCategory> listCategory() {
return null;
public List<ItemCategoryDTO> listCategory() {
return itemCategoryMapper.listRootCategory();
}
}
<?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.muses.taoshop.item.mapper.ItemBrandMapper" >
<resultMap id="baseResultMap" type="com.muses.taoshop.item.dto.ItemBrand" >
<resultMap id="baseResultMap" type="com.muses.taoshop.item.entity.ItemBrand" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="brand_name" property="brandName" jdbcType="VARCHAR" />
<result column="last_modify_time" property="lastModifyTime" jdbcType="TIMESTAMP" />
......
<?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.muses.taoshop.mapper.ItemCategoryMapper" >
<mapper namespace="com.muses.taoshop.item.mapper.ItemCategoryMapper" >
<resultMap id="BaseResultMap" type="com.muses.taoshop.item.entity.ItemCategory" >
<id column="id" property="id" jdbcType="BIGINT" />
<result column="category_name" property="categoryName" jdbcType="VARCHAR" />
......@@ -9,14 +9,17 @@
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
<sql id="BaseColumnList" >
id, category_name, sjid, last_modify_time, create_time
</sql>
<!-- 获取所有的根据品类信息-->
<select id="listRootCategory" resultType="ItemCategory">
SELECT id , category_name
SELECT
<include refid="BaseColumnList" />
FROM item_category t
<where>
t.sjid = 0
</where>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册