代码编写笔记

1.文件下载代码报错------文件夹不存在,所以无法创建文件。

2.无法分别对一个id下的数据统计计算-----group by
3.sql语句日期格式化 DATE_FORMAT(nm.CREATE_TIME,’%Y-%m-%d %H:%i:%s’),
一个月以前DATE_ADD(NOW(),INTERVAL -1 month)
unix_timestamp(string date) 获取时间戳
4.跨域名访问ajax添加属性------xhrFields: {withCredentials: true },
5.idea启动项目报错,端口被占用,打开任务管理器,关掉java.exe程序,启动项目即可
6.连接ftp选择sftp连接。
7.sql语句 if(3>2,1,2)假如前面的为true 则为1,前面为false,则为2。
java语句 3>2?1:2假如前面的为true 则为1,前面为false,则为2。
8.idea项目无法启动,找不到tomcat,file——setting——plugins搜索tomcat,如果已勾选则取消勾选应用后再重新搜索勾选然后配置tomat。run——edit configurstions
9.获取本周周一的日期(星期一为一周的开始)

LocalDate today = LocalDate.now();
LocalDate toweekMonday = today.with(DayOfWeek.MONDAY);

10.数据库字符串排序时,将字符串转换成数字排序,CAST(字段名 as SIGNED)若有中英文字符,可通过substring截取再排序
格式化成年月日 CAST(NOW() AS DATE)
11.判断非空时!=null&!.equals("")避免空指针
12. date_sub(‘2016-08-01’,interval 1 day) 获取前一天时间
13. js保留两位小数 .toFixed(2)
14. double保留两位小数

DecimalFormat df = new DecimalFormat("0.00");
		return df.format(d);

假如格式化的数字是小于1的小数0.15,用#.00会被格式化成.15,用0.00是0.15
15. 4-20ma转瞬时流量 (测量电流-4)/16 *量程 为测量结果。
16. 报错 Mapped Statements collection does not contain value for
可能是xml文件文件名和mapper不一样 ,方法名不一样 或者xml文件没有编译,没有这个文件,总之找不到对应的方法
17.数据库里的数据是空 , 但是!=‘’和!=null都筛选不出来,用isnull(id)。
18.vim模式下,insert进入文件输入模式,esc退出文件输入模式,shift+:进入命令输入模式 wq退出
19.格式化一天前的时间 DATE_FORMAT( date_sub(NOW(),interval 1 day),’%Y-%m-%d’)
20. 查询上一个插入的id: select LAST_INSERT_ID()

  1. //1.查看当前数据库锁表的情况
    SELECT * FROM information_schema.INNODB_TRX;
    //2.杀掉查询结果中锁表的trx_mysql_thread_id
    kill trx_mysql_thread_id

show processlist 分析数据库进程
kill id 杀进程
22.专门捕获dao层sql异常 DataAccessException

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个问题比较广泛,需要分步骤讲解。以下是一些可能的步骤和代码示例: 1. 创建一个笔记类(Note): ```java public class Note { private int id; private String title; private String content; private Date createdDate; private Date modifiedDate; public Note() { // 构造函数 } // getter 和 setter 方法 // 重写 toString 方法,方便调试 @Override public String toString() { return "Note{" + "id=" + id + ", title='" + title + '\'' + ", content='" + content + '\'' + ", createdDate=" + createdDate + ", modifiedDate=" + modifiedDate + '}'; } } ``` 2. 创建一个数据库帮助类(DbHelper): ```java public class DbHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "notes.db"; private static final int DATABASE_VERSION = 1; private static final String TABLE_NAME = "notes"; private static final String COLUMN_ID = "_id"; private static final String COLUMN_TITLE = "title"; private static final String COLUMN_CONTENT = "content"; private static final String COLUMN_CREATED_DATE = "created_date"; private static final String COLUMN_MODIFIED_DATE = "modified_date"; // SQL 语句 private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " + TABLE_NAME + " (" + COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_TITLE + " TEXT," + COLUMN_CONTENT + " TEXT," + COLUMN_CREATED_DATE + " INTEGER," + COLUMN_MODIFIED_DATE + " INTEGER)"; public DbHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(SQL_CREATE_ENTRIES); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // 数据库升级 } } ``` 3. 创建一个数据访问层(NoteDao): ```java public class NoteDao { private SQLiteDatabase db; private DbHelper dbHelper; public NoteDao(Context context) { dbHelper = new DbHelper(context); db = dbHelper.getWritableDatabase(); } public long add(Note note) { ContentValues values = new ContentValues(); values.put(DbHelper.COLUMN_TITLE, note.getTitle()); values.put(DbHelper.COLUMN_CONTENT, note.getContent()); values.put(DbHelper.COLUMN_CREATED_DATE, note.getCreatedDate().getTime()); values.put(DbHelper.COLUMN_MODIFIED_DATE, note.getModifiedDate().getTime()); return db.insert(DbHelper.TABLE_NAME, null, values); } public int update(Note note) { ContentValues values = new ContentValues(); values.put(DbHelper.COLUMN_TITLE, note.getTitle()); values.put(DbHelper.COLUMN_CONTENT, note.getContent()); values.put(DbHelper.COLUMN_MODIFIED_DATE, note.getModifiedDate().getTime()); String whereClause = DbHelper.COLUMN_ID + "=?"; String[] whereArgs = { String.valueOf(note.getId()) }; return db.update(DbHelper.TABLE_NAME, values, whereClause, whereArgs); } public int delete(Note note) { String whereClause = DbHelper.COLUMN_ID + "=?"; String[] whereArgs = { String.valueOf(note.getId()) }; return db.delete(DbHelper.TABLE_NAME, whereClause, whereArgs); } public List<Note> getAll() { List<Note> notes = new ArrayList<>(); Cursor cursor = db.query(DbHelper.TABLE_NAME, null, null, null, null, null, DbHelper.COLUMN_MODIFIED_DATE + " DESC"); while (cursor.moveToNext()) { Note note = new Note(); note.setId(cursor.getInt(cursor.getColumnIndex(DbHelper.COLUMN_ID))); note.setTitle(cursor.getString(cursor.getColumnIndex(DbHelper.COLUMN_TITLE))); note.setContent(cursor.getString(cursor.getColumnIndex(DbHelper.COLUMN_CONTENT))); note.setCreatedDate(new Date(cursor.getLong(cursor.getColumnIndex(DbHelper.COLUMN_CREATED_DATE)))); note.setModifiedDate(new Date(cursor.getLong(cursor.getColumnIndex(DbHelper.COLUMN_MODIFIED_DATE)))); notes.add(note); } cursor.close(); return notes; } } ``` 4. 创建一个笔记列表界面(NoteListActivity): ```java public class NoteListActivity extends AppCompatActivity { private static final int REQUEST_CODE_ADD = 1; private static final int REQUEST_CODE_EDIT = 2; private ListView listView; private List<Note> notes; private NoteDao noteDao; private ArrayAdapter<Note> adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_list); noteDao = new NoteDao(this); listView = findViewById(R.id.list_view); notes = noteDao.getAll(); adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, notes); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Note note = notes.get(position); Intent intent = new Intent(NoteListActivity.this, NoteEditActivity.class); intent.putExtra("note", note); startActivityForResult(intent, REQUEST_CODE_EDIT); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { switch (requestCode) { case REQUEST_CODE_ADD: Note note = (Note) data.getSerializableExtra("note"); long id = noteDao.add(note); note.setId((int) id); notes.add(0, note); adapter.notifyDataSetChanged(); break; case REQUEST_CODE_EDIT: note = (Note) data.getSerializableExtra("note"); noteDao.update(note); adapter.notifyDataSetChanged(); break; } } } public void onAddButtonClick(View view) { Intent intent = new Intent(this, NoteEditActivity.class); startActivityForResult(intent, REQUEST_CODE_ADD); } } ``` 5. 创建一个笔记编辑界面(NoteEditActivity): ```java public class NoteEditActivity extends AppCompatActivity { private EditText titleEditText; private EditText contentEditText; private Note note; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_note_edit); titleEditText = findViewById(R.id.title_edit_text); contentEditText = findViewById(R.id.content_edit_text); note = (Note) getIntent().getSerializableExtra("note"); if (note == null) { note = new Note(); } else { titleEditText.setText(note.getTitle()); contentEditText.setText(note.getContent()); } } public void onSaveButtonClick(View view) { note.setTitle(titleEditText.getText().toString()); note.setContent(contentEditText.getText().toString()); note.setModifiedDate(new Date()); Intent intent = new Intent(); intent.putExtra("note", note); setResult(RESULT_OK, intent); finish(); } } ``` 这些代码只是一个简单的示例,实际开发中需要根据具体需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值