你這個(gè)只是一個(gè)方法,而且是數(shù)據(jù)分析,應(yīng)該放在服務(wù)層,而且你這里還沒有返回值,怎么告訴控制層?
目前創(chuàng)新互聯(lián)已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、瀍河網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
第一:服務(wù)層:
public String audit(Long spuId,String status) {
Spu spu =new Spu();
spu.setId(spuId);
spu.setStatus(status);
if ("1".equals(status)){//審核通過
spu.setIsMarketable("1");//自動(dòng)上架
}else{
如果不是,怎么怎么樣
}
spuMapper.updateByPrimaryKeySelective(spu);
return 某個(gè)狀態(tài)值
}
第二:控制層:
前端傳進(jìn)來參數(shù),調(diào)用服務(wù)層方法,返回前端
package entity;
public class Market {
private int id;//id
private int num;//數(shù)量
private String goods;//商品
private double price;//價(jià)格
public Market(int id, int num, String goods, double price) {
super();
this.id = id;
this.num = num;
this.goods = goods;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getGoods() {
return goods;
}
public void setGoods(String goods) {
this.goods = goods;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public double calc( ){
double sum=price*num;
System.out.println("您消費(fèi)共計(jì):"+sum+"¥");
return sum;
}
}
package test;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import entity.Market;
public class Test {
private static MapInteger,Market goods=new HashMapInteger, Market();
public static void main(String[] args) {
System.out.println("-------超市計(jì)價(jià)系統(tǒng)-------");
String goods1="可口可樂";
String goods2="爆米花";
String goods3="益達(dá)";
printTable("編號(hào)","商品","價(jià)格");
printTable("1",goods1,"3.0¥");
printTable("2",goods2,"5.0¥");
printTable("3",goods3,"10.0¥");
goods.put(1, new Market(1, 1, goods1, 3.0));
goods.put(2, new Market(2, 1, goods2, 5.0));
goods.put(3, new Market(3, 1, goods3, 10.0));
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入商品的編號(hào):");
int num = input.nextInt();
System.out.println("請(qǐng)輸入商品的數(shù)量");
int amount = input.nextInt();
Market market = goods.get(num);
market.setNum(amount);
market.calc();
}
private static void printTable(String row1,String row2,String row3 ) {
System.out.print(row1);
int times=12;
if (row2!="商品") {
times=5;
}
for (int i = 0; i times; i++) {
System.out.print(" ");
}
System.out.print(row2);
for (int i = 0; i 10; i++) {
System.out.print(" ");
}
System.out.print(row3);
System.out.println("\n");
}
}
//測(cè)試結(jié)果:
-------超市計(jì)價(jià)系統(tǒng)-------
編號(hào) 商品 價(jià)格
1 可口可樂 3.0¥
2 爆米花 5.0¥
3 益達(dá) 10.0¥
請(qǐng)輸入商品的編號(hào):
3
請(qǐng)輸入商品的數(shù)量
5
您消費(fèi)共計(jì):50.0¥
import java.util.Scanner;
public class colPrice{
public static void main(String[] args){
double[] price = new double[10];
double totalPrice = 0;
System.out.println("請(qǐng)輸入商品價(jià)格:");
for(int i=0;i10;i++){
System.out.print(i+1+": ");
Scanner in = new Scanner( System.in);
price[i] = in.nextDouble();
}
System.out.println("");
for(int i= 0;iprice.length;i++){
totalPrice+=price[i];
}
System.out.println("商品總價(jià)格是:"+totalPrice);
}
}