一、SpringBoot学习,自己练手的一个小项目,拿来和博友分享。先来一段演示,有想交流或者学习的博友,不要忘了加关注哦
二、微信小程序部分代码
onLoad: function(){
var goodsList = [];
var that = this;
wx.request({
url: 'http://localhost:9002/fruits',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: function (res) {
console.log(res.data + "你是从后台来的ma?");
that.setData({
goodsList: res.data
})
},
fail: function (res) {
console.log('submit fail');
},
complete: function (res) {
console.log('submit complete');
},
})
},
三、后台详细架构情况
1、数据库
drop table if exists tt_fruits;
create table tt_fruits(
id int PRIMARY KEY not null AUTO_INCREMENT,
detail varchar(100),
image varchar(100),
parameter varchar(100),
price double,
service varchar(100),
stock varchar(100),
title varchar(100),
num int
);
insert into tt_fruits values(1,'美国黄桃','/image/contentImage/b.jpg','优质黄桃倆个,400mL饮用水',25,'不支持退货','有货','爽口黄桃汁',0)
insert into tt_fruits values(2,'澳大利亚香蕉鲜榨','/image/contentImage/a.jpg','香蕉倆个,400mL饮用水',20,'不支持退货','有货','新鲜香蕉汁',0)
2、项目代码目录
3、jar包
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.example
xianguoyuan
0.0.1-SNAPSHOT
war
xianguoyuan
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.3.RELEASE
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-starter-test
test
mysql
mysql-connector-java
org.springframework.boot
spring-boot-maven-plugin
4、Controller
package com.example.demo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.entity.Fruits;
import com.example.demo.serviceimpl.TtFruitsServiceImpl;
@RestController
@EnableAutoConfiguration
public class TtFruitsController {
@Autowired
TtFruitsServiceImpl ttFruits;
@RequestMapping("/fruits")
@ResponseBody
public ListfindAll(){
Listlist=ttFruits.findAll();
// for (Fruits fruits : list) {
// System.out.println(fruits);
// }
return list;
}
}
5、service
package com.example.demo.service;
import java.util.List;
import com.example.demo.entity.Fruits;
public interface TtFruitsService {
public List findAll();
}
6、serviceImpl
package com.example.demo.serviceimpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.demo.dao.TtFruitsDao;
import com.example.demo.entity.Fruits;
import com.example.demo.service.TtFruitsService;
@Service
public class TtFruitsServiceImpl implements TtFruitsService{
@Autowired
TtFruitsDao ttFruitsDao;
@Override
public List findAll() {
// TODO Auto-generated method stub
return ttFruitsDao.findAll();
}
}
7、dao
package com.example.demo.dao;
import java.util.List;
import com.example.demo.entity.Fruits;
public interface TtFruitsDao {
public List findAll();
}
8、entity
package com.example.demo.entity;
public class Fruits {
@Override
public String toString() {
return "Fruits [id=" + id + ", detail=" + detail + ", image=" + image + ", parameter=" + parameter + ", price="
+ price + ", service=" + service + ", stock=" + stock + ", title=" + title + ", num=" + num + "]";
}
private int id;
private String detail;
private String image;
private String parameter;
private Double price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getParameter() {
return parameter;
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public String getStock() {
return stock;
}
public void setStock(String stock) {
this.stock = stock;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
private String service;
private String stock;
private String title;
private int num;
}
9、application
package com.example.demo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@MapperScan("com.example.demo.dao")
public class XianguoyuanApplication {
public static void main(String[] args) {
SpringApplication.run(XianguoyuanApplication.class, args);
}
}
10、mapper
11、application、properties
server.port=9002
#spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
#spring.datasource.url=jdbc:oracle:thin:@dx.anhuily.com:15210:orcl
#spring.datasource.username=NC_WEB
#spring.datasource.password=KWT2016
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/xianguoyuan?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=yh199210
mybatis.mapperLocations=classpath:mapper/*.xml
mybatis.typeAliasesPackage=com.example.demo.entity