Home > Back-end >  Requirements: database shows Numbers, after get into words
Requirements: database shows Numbers, after get into words

Time:10-16

Such as a database has a field for the types,
Id types
1 1
2 2
3 3
1, 2, 3 4
Springboot development after get the data value of this field,
Displays text types=1 then: state 1
Types=2:2
If it is types=1, 2, 3 shows: state 1, 2, 3, commas

CodePudding user response:

 
SELECT the IF (types='1', '1', the IF (op_type='2', '2', '3' state)) FROM tableName;

Can use SQL to solve this, also can replace with Java function to solve, my knowledge lays out a little, SQL is relatively trouble

CodePudding user response:

Why not directly into state 1, 2, state 3

CodePudding user response:

The
reference 1/f, scene at the beginning of JingChu, reply:
 
SELECT the IF (types='1', '1', the IF (op_type='2', '2', '3' state)) FROM tableName;

This can use SQL to solve, also can replace with Java function to solve, I knowledge lays out a bit, SQL is relatively trouble

I write in springboot implementation class, our boss told me to use enumeration, I don't know how to do

CodePudding user response:

Can write a method to invoke this method and through the for loop for each data corresponding results:
Public String getTypesResult (int types) {
The StringBuilder sb=new StringBuilder ();
If (types==1) {
Sb. Append (" state 1 ");
} else if (types==2) {
Sb. Append (" state 2 ");
{} else if (types==3)
Sb. Append (" state 3 ");
}
Return sb. ToString ();
}

CodePudding user response:

refer to the second floor pinoco response:
why not directly put into state 1, 2, state 3?
will be kicked out of the little genius

CodePudding user response:

As it happens this two days is just written
Fyi
SELECT

W.t arget_station_xx,
CASE p. hift_xx
WHEN '0' THEN
'not received'
WHEN '1' THEN
'received'
WHEN '2' THEN
'has reached'
END shift_status
The FROM
Xx p
LEFT the JOIN
Xx w
ON
Xx
WHERE
xx

CodePudding user response:

reference 4 floor meet_zzs response:
can write a method to invoke this method and through the for loop each data corresponding results:
Public String getTypesResult (int types) {
The StringBuilder sb=new StringBuilder ();
If (types==1) {
Sb. Append (" state 1 ");
} else if (types==2) {
Sb. Append (" state 2 ");
{} else if (types==3)
Sb. Append (" state 3 ");
}
Return sb. ToString ();
}

The front topic didn't review well, replace it directly, also simple
Public String getTypesResult (String types) {
String types="1";
If (types. IndexOf (" 1 ")!=1) {
Types=types. The replace (" 1 ", "state 1");
}
If (types. IndexOf (" 2 ").=2) {
Types=types. The replace (" 2 ", "2");
}
If (types. IndexOf (" 3 "). {
=3)Types=types. The replace (" 3 ", "state 3");
}
The return types.
}

CodePudding user response:

refer to 7th floor meet_zzs response:
Quote: refer to 4th floor meet_zzs response:
can write a method to invoke this method and through the for loop each data corresponding results:
Public String getTypesResult (int types) {
The StringBuilder sb=new StringBuilder ();
If (types==1) {
Sb. Append (" state 1 ");
} else if (types==2) {
Sb. Append (" state 2 ");
{} else if (types==3)
Sb. Append (" state 3 ");
}
Return sb. ToString ();
}

The front topic didn't review well, replace it directly, also simple
Public String getTypesResult (String types) {
String types="1";
If (types. IndexOf (" 1 ")!=1) {
Types=types. The replace (" 1 ", "state 1");
}
If (types. IndexOf (" 2 ").=2) {
Types=types. The replace (" 2 ", "2");
}
If (types. IndexOf (" 3 "). {
=3)Types=types. The replace (" 3 ", "state 3");
}
The return types.
}

If you replace type="1, 2, 3", the output is: state 1, 2, 3, you need to adapt to all scenarios, such as (2, 3), (1, 3)

CodePudding user response:

reference only 8 floor,,, reply:
Quote: refer to 7th floor meet_zzs response:
Quote: refer to 4th floor meet_zzs response:
can write a method to invoke this method and through the for loop each data corresponding results:
Public String getTypesResult (int types) {
The StringBuilder sb=new StringBuilder ();
If (types==1) {
Sb. Append (" state 1 ");
} else if (types==2) {
Sb. Append (" state 2 ");
{} else if (types==3)
Sb. Append (" state 3 ");
}
Return sb. ToString ();
}

The front topic didn't review well, replace it directly, also simple
Public String getTypesResult (String types) {
String types="1";
If (types. IndexOf (" 1 ")!=1) {
Types=types. The replace (" 1 ", "state 1");
}
If (types. IndexOf (" 2 ").=2) {
Types=types. The replace (" 2 ", "2");
}
If (types. IndexOf (" 3 "). {
=3)Types=types. The replace (" 3 ", "state 3");
}
The return types.
}

If you replace type="1, 2, 3", the output is: state 1, 2, 3, you need to adapt to all scenarios, such as (2, 3), (1, 3)

Dubious write again wrong (cry smile smile)
Public String getTypesResult (String types) {
If (types. IndexOf (" 1 ")!=1) {
Types=types. The replace (" 1 ", "state 1");
}
If (types. IndexOf (" 2 ").=1) {
Types=types. The replace (" 2 ", "2");
}
If (types. IndexOf (" 3 ").=1) {
Types=types. The replace (" 3 ", "state 3");
}
The return types.
}

CodePudding user response:

The switch, the if... Else if... Else if... Also, your boss must use the enumeration, use it for younullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related