把 mybatis 整合到其中
parent
85846516f1
commit
aedecc44d1
|
@ -22,6 +22,19 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -1,13 +1,20 @@
|
|||
package cn.iocoder.mall.product;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口
|
||||
public class ProductRestApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ProductRestApplication.class, args);
|
||||
ConfigurableApplicationContext ctx = SpringApplication.run(ProductRestApplication.class, args);
|
||||
DataSource ds = ctx.getBean(DataSource.class);
|
||||
System.out.println(ds);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.mall.product.controller;
|
||||
package cn.iocoder.mall.product.controller.user;
|
||||
|
||||
import cn.iocoder.mall.product.vo.ProductCategoryVO;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
@ -10,7 +10,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/category")
|
||||
@RequestMapping("user/product/category")
|
||||
public class ProductCategoryController {
|
||||
|
||||
// TODO 获得父编号为 id 的分类们 后面,使用 swagger 注释
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.mall.product.controller;
|
||||
package cn.iocoder.mall.product.controller.user;
|
||||
|
||||
import cn.iocoder.mall.product.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.product.service.ProductSpuService;
|
||||
|
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/product/spu")
|
||||
@RequestMapping("user/product/spu")
|
||||
public class ProductSpuController {
|
||||
|
||||
@Autowired
|
|
@ -1,15 +0,0 @@
|
|||
package cn.iocoder.mall.product.dao;
|
||||
|
||||
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ProductSpuDAO {
|
||||
|
||||
public ProductSpuDO selectById(Integer id) {
|
||||
ProductSpuDO spu = new ProductSpuDO();
|
||||
spu.setId(id);
|
||||
return spu;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package cn.iocoder.mall.product.dao;
|
||||
|
||||
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProductSpuMapper {
|
||||
|
||||
ProductSpuDO selectById(Integer id);
|
||||
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package cn.iocoder.mall.product.service;
|
||||
|
||||
import cn.iocoder.mall.product.bo.ProductSpuBO;
|
||||
import cn.iocoder.mall.product.dao.ProductSpuDAO;
|
||||
import cn.iocoder.mall.product.dao.ProductSpuMapper;
|
||||
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
|
|||
public class ProductSpuService implements cn.iocoder.mall.product.service.api.ProductSpuService {
|
||||
|
||||
@Autowired
|
||||
private ProductSpuDAO productSpuDAO;
|
||||
private ProductSpuMapper productSpuDAO;
|
||||
|
||||
public ProductSpuBO getProductSpu(Integer id) {
|
||||
ProductSpuDO productSpuDO = productSpuDAO.selectById(id);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
spring:
|
||||
# datasource
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:33061/mall_product?useSSL=false
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
# mybatis
|
||||
mybatis:
|
||||
config-location: classpath:mybatis/mybatis-config.xml
|
||||
mapper-locations: classpath:mybatis/mapper/*.xml
|
||||
type-aliases-package: cn.iocoder.mall.product.dataobject
|
|
@ -0,0 +1,12 @@
|
|||
<?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="cn.iocoder.mall.product.dao.ProductSpuMapper">
|
||||
|
||||
<select id="selectById" parameterType="Integer" resultType="ProductSpuDO">
|
||||
SELECT
|
||||
id
|
||||
FROM product_spu
|
||||
WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<settings>
|
||||
<!-- 使用驼峰命名法转换字段。 -->
|
||||
<setting name="mapUnderscoreToCamelCase" value="true"/>
|
||||
</settings>
|
||||
|
||||
<typeAliases>
|
||||
<typeAlias alias="Integer" type="java.lang.Integer"/>
|
||||
<typeAlias alias="Long" type="java.lang.Long"/>
|
||||
<typeAlias alias="HashMap" type="java.util.HashMap"/>
|
||||
<typeAlias alias="LinkedHashMap" type="java.util.LinkedHashMap"/>
|
||||
<typeAlias alias="ArrayList" type="java.util.ArrayList"/>
|
||||
<typeAlias alias="LinkedList" type="java.util.LinkedList"/>
|
||||
</typeAliases>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue