偌衣學習系統:1 使用 pojo目錄使用 domain做爲名字spring
2 使用validate 的方法:設置非空 和文字的長度,sql
設置自定義的 註解防曬apache
/** 系統內置(Y是 N否) */
@Excel(name = "系統內置", readConverterExp = "Y=是,N=否")
private String configType;數組
@NotBlank(message = "參數名稱不能爲空")
@Size(min = 0, max = 100, message = "參數名稱不能超過100個字符")
public String getConfigName()
{
return configName;
}3 正常狀況下,字母項目編譯mvn package是能夠編輯打包的,不能的話是配置錯了mybatis
4 只有pojo類被加入的方法纔會真正的追加打印 mvc
public String toString() {
return new ToStringBuilder(this).append("ssn", ssn).append("year", year).append("lastName",
lastName).toString();
}
maven依賴是:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
5 經過建立實體類集成 serializable的方式來進行序列化
public class BaseEntity implements Serializable
而後其餘類來集成他
同時經過JsonFormat來格式化
/** 建立時間 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;app
使用JsonFormat 主要用於 後臺到前臺的轉換, 能夠用再get和屬性名上
//設置時區爲上海時區,時間格式本身據需求定。
@JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8")
private Date testTime;dom
須要依賴的包是maven
2.註解@DateTimeFormat學習
<!-- joda-time -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
2.在controller層咱們使用spring mvc 表單自動封裝映射對象時,咱們在對應的接收前臺數據的對象的屬性上加@@DateTimeFormat
@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date symendtime;
註解@JsonFormat主要是後臺到前臺的時間格式的轉換
註解@DataFormAT主要是先後到後臺的時間格式的轉換
5 自定義註解的方式
/**
* 自定義導出Excel數據註解
*
* @author ruoyi
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Excel
{
6 mybatis 使用公共的引用的方法:
定義兩個sql,直接include 引入,同時 用refid來關聯
<sql id="selectConfigVo">
select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark
from sys_config
</sql>
<!-- 查詢條件 -->
<sql id="sqlwhereSearch">
<where>
<if test="configId !=null">
and config_id = #{configId}
</if>
<if test="configKey !=null and configKey != ''">
and config_key = #{configKey}
</if>
</where>
</sql>
<select id="selectConfig" parameterType="SysConfig" resultMap="SysConfigResult">
<include refid="selectConfigVo"/>
<include refid="sqlwhereSearch"/>
</select>
7 使用mybatis 數組進行循環的方法
public int deleteConfigByIds(String[] configIds);
<delete id="deleteConfigByIds" parameterType="String">
delete from sys_config where config_id in
<foreach item="configId" collection="array" open="(" separator="," close=")">
#{configId}
</foreach>
</delete>
8 有Long類型
9 循環的第二個方式
public int updateDeptChildren(@Param("depts") List<SysDept> depts);
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
where dept_id in
<foreach collection="depts" item="item" index="index"
separator="," open="(" close=")">
#{item.deptId}
</foreach>
10 定時任務 xxx
2 schedule 中止job的方法,刪除,回覆,馬上運行的方法
Long jobId = job.getJobId();
String jobGroup = job.getJobGroup();
job.setStatus(ScheduleConstants.Status.PAUSE.getValue());
int rows = jobMapper.updateJob(job);
if (rows > 0)
{
scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup));
}
scheduler.resumeJob(ScheduleUtils.getJobKey(jobId, jobGroup));
scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup));
馬上運行job的方法
String jobGroup = job.getJobGroup();
SysJob properties = selectJobById(job.getJobId());
// 參數
JobDataMap dataMap = new JobDataMap();
dataMap.put(ScheduleConstants.TASK_PROPERTIES, properties);
scheduler.triggerJob(ScheduleUtils.getJobKey(jobId, jobGroup), dataMap);
更新任務就是刪除後新建任務的方法
/**
* 更新任務
*
* @param job 任務對象
* @param jobGroup 任務組名
*/
public void updateSchedulerJob(SysJob job, String jobGroup) throws SchedulerException, TaskException
{
Long jobId = job.getJobId();
// 判斷是否存在
JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup);
if (scheduler.checkExists(jobKey))
{
// 防止建立時存在數據問題 先移除,而後在執行建立操做
scheduler.deleteJob(jobKey);
}
ScheduleUtils.createScheduleJob(scheduler, job);
此時的schedule已經注入到了 spring @Autowired private Scheduler scheduler;