标签:prope lis int 数据库 pen ack rgs enc gap
<!-- spring boot 整合mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency> <!-- MYSQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
package cn.java.controller; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; /* * spring boot 启动程序 */ @SpringBootApplication(scanBasePackages= {"cn.java.controller","cn.java.service.impl"}) @EnableAutoConfiguration //配置mapper层扫描 @MapperScan(basePackages="cn.java.mapper") public class StartApplication { public static void main(String[] args) { SpringApplication.run(StartApplication.class, args); } }
控制层GoodController
package cn.java.controller; import java.util.List; import java.util.Map; 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.ResponseBody; import cn.java.service.GoodService; @Controller @RequestMapping("/goods/") public class GoodController { @Autowired private GoodService goodService; //获取goods表中所有数据 @RequestMapping("/selectAllGoods.do") @ResponseBody public List<Map<String,Object>> selectAllGoods(){ return goodService.getAll(); } }
业务层
package cn.java.service; import java.util.List; import java.util.Map; public interface GoodService { List<Map<String, Object>> getAll(); }
package cn.java.service.impl; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import cn.java.mapper.GoodMapper; import cn.java.service.GoodService; @Service public class GoodServiceImpl implements GoodService { /* * 获取springboot库下goods表中所有的数据 */ @Autowired private GoodMapper goodMapper; /* * 查询所有商品 */ /* (non-Javadoc) * @see cn.java.service.impl.GoodService#getAll() */ @Override public List<Map<String,Object>> getAll(){ return goodMapper.getAllGoods(); } }
DAO层
package cn.java.mapper; import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Select; public interface GoodMapper { @Select("SELECT * FROM goods") public List<Map<String,Object>> getAllGoods(); }
application.properties
#update tomcat port server.port=8888 #config datasource(mysql) spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql:///springboot spring.datasource.username=root spring.datasource.password=78978r
数据库springboot
CREATE TABLE `springboot`.`goods`( `id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT ‘主键‘, `good_name` VARCHAR(40) COMMENT ‘商品名称‘, `good_price` FLOAT(10,2) COMMENT ‘商品单价‘, `good_phone` VARCHAR(20) COMMENT ‘商品联系电话‘, `good_address` VARCHAR(40) COMMENT ‘商品地址‘, `good_num` INT COMMENT ‘商品库存‘, PRIMARY KEY (`id`) );
控制层与业务层 业务层与DAO层 通过接口连接
标签:prope lis int 数据库 pen ack rgs enc gap
原文地址:https://www.cnblogs.com/mzdljgz/p/10508148.html