java实际开发中遇到的问题(与NET区别)

1 循环语法

for(RTeacherSubject teacher : teacherSubjectList)

      {     System.out.println(teacher.getTeacherclasssubjectid());

      }

2 MYSQL语法

SELECT DISTINCT tsc.ClassID, CONCAT( tsc.grade ,'年级',tsc.name )AS className FROM

      cloud_ArchivesManage.T_TeacherInfo tti

      JOIN

      cloud_ArchivesManage.R_Teacher_Subject rts ON tti.UserID=rts.TeacherID

      JOIN cloud_ArchivesManage.T_SchoolClass tsc ON tsc.ClassID=rts.ClassID

      WHERE tti.UserID=13969823

SQLServer中

SELECT DISTINCT tsc.ClassID, CAST( tsc.grade AS

        VARCHAR)+'年级'+tsc.name as className FROM

        cloud_ArchivesManage.dbo.T_TeacherInfo tti

        JOIN

        cloud_ArchivesManage.dbo.R_Teacher_Subject rts ON tti.UserID=rts.TeacherID

        JOIN cloud_ArchivesManage.dbo.T_SchoolClass tsc ON tsc.ClassID=rts.ClassID

        WHERE tti.UserID=13969823

3 条件判断

<if test="ssid != null and ssid!='' and ssid!='-1'">

        AND tss.SSID=#{ssid,jdbcType=VARCHAR}

</if>

4 数据库isnull和ifnull问题

Sql中:ISNULL(s.num,0) AS studentNumber

MySql中: IFNULL(s.num,0) AS studentNumber

5 MYBATITS中问题

求总数量的时候注意返回类型

 

6 实例化问题

List<RClassVersion> classVersionList = new ArrayList<RClassVersion>();

 

7 自增长ID为null

 

8 DATETIME的数据库类型

TIMESTAMP

 

 

9 数据读取少一条的原因

LIMIT 0,3  默认从0开始

 

10 like查询

 

and scc.Name  like CONCAT('%','${classname}','%' )

11获取每月里的day

Calendar cal = Calendar.getInstance();

Int day=cal.get(Calendar.DATE));

12正则解析

String regex = "\\{[^\\{*].*\\}";

      Pattern pattern = Pattern.compile(regex);

      Matcher matcher = pattern.matcher(res);

JSONObject jsonobject = JSONObject.fromObject(matcher.group(0));

 

13 json解析

JSONObject jsonobject = JSONObject.fromObject(matcher.group(0));

 

数据里面嵌套数据

                   JSONArray ja1 = jsonobject.getJSONArray("Data");

                   List<ProductInfo> product = new ArrayList<ProductInfo>();

                   try {

                            for (int i = 0; i < ja1.size(); i++) {

                                     JSONObject jsonItem = ja1.getJSONObject(i);

                                     ProductInfo item = new ProductInfo();

                                     item.setProductid(jsonItem.getInt("ProductID"));

                                     item.setProductname(jsonItem.getString("ProductName"));

                           

                                     item.setStatus(jsonItem.getInt("Status"));

                                     item.setLogoimg(jsonItem.getString("LogoImg"));

                                     item.setUrl(jsonItem.getString("Url"));

                                    

 

                                     product.add(item);

                            }

                   } catch (JSONException e) {

                            e.printStackTrace();

                   }

一层数据

String regex = "\\{[^\\{*].*\\}";

                   Pattern pattern = Pattern.compile(regex);

                   Matcher matcher = pattern.matcher(res);

                   if (matcher.find()) {

                            JSONObject jsonObject = JSONObject.fromObject(matcher.group(0)); 

                            try {

                                     if (jsonObject.getInt("Code") == 200 && jsonObject.getBoolean("Data")) {

                                               json.setMessage(jsonObject.getString("Message"));

                                               json.setUrl(url);

                                               json.setState(true);

                                     } else {

                                               json.setMessage(jsonObject.getString("Message"));

                                               json.setUrl(url);

                                               json.setState(false);

                                     }

                            } catch (JSONException e) {

                                     e.printStackTrace();

                            }

                   }

 

14 substring

String str = url.substring(url.length() - 1, url.length());

从哪位开始到哪位结束

 

15 jdbcType不写的问题

D_TYPE = #{awbType,jdbcType=VARCHAR} 中的jdbcType 不写有啥影响

答:不写为空时会报错,写了就不会

16 中文字符转为GB2312方法

         public String changeCharset(String str, String newCharset) throws UnsupportedEncodingException {

                   if (str != null) {

                            // 用默认字符编码解码字符串。

                            byte[] bs = str.getBytes();

                            // 用新的字符编码生成字符串

                            return new String(bs, newCharset);

                   }

                   return null;

         }

17 字符串拼接方法

C#

string res = string.Format("key={0}&userID={1}&productID={2}&dataType={3}&name={4}&schoolID={5}", key, userID, productId, "json", usercenterName, schoolAreaID)

 

java实现
String param1 = String.format("key=%1$s&userID=%2$s&productID=%3$s&dataType=%4$s&name=%5$s&schoolID=%6$s", key, userid,

                                     productId, "json", userCenterName, schoolAreaID);

 

%s 字符串类型 如”mingrisoft”

%c 字符类型 ‘m’

%b 布尔类型 true

%d 整数类型(十进制) 99

%x 整数类型(十六进制) FF

%o 整数类型(八进制) 77

%f 浮点类型 99.99

%a 十六进制浮点类型 FF.35AE

%e 指数类型 9.38e+5

%g 通用浮点类型(f和e类型中较短的)

%% 百分比类型 %

%n 换行符

%tx 日期与时间类型(x代表不同的日期与时间转换符)

18 tomcat启动失败原因

Mapper.xml中问题,区分大小写

posted on 2016-02-17 11:05  以勤补拙  阅读(764)  评论(0编辑  收藏  举报