修改org/pqh/core/util/DBAction.java标识符

master
luffy9412 7 years ago
parent af40f9174d
commit 79eced21e7
  1. 18
      core/src/main/java/org/pqh/core/config/HibernateConfig.java
  2. 14
      core/src/main/java/org/pqh/core/service/BaseService.java
  3. 29
      core/src/main/java/org/pqh/core/util/DBAction.java
  4. 2
      web/src/main/java/org/pqh/achieve/controller/BaseController.java
  5. 4
      web/src/main/resources/config.properties

@ -14,25 +14,32 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
/** /**
* Created by reborn on 2017/7/28. * Created by reborn on 2017/7/28.
*/ */
@Configuration @Configuration
@PropertySource("classpath:hibernate.properties") @PropertySource("classpath:config.properties")
@EnableTransactionManagement @EnableTransactionManagement
public class HibernateConfig{ public class HibernateConfig{
private Logger log= LogManager.getLogger(); private Logger log= LogManager.getLogger();
@Value("${hibernate.connection.pool_size}")
private String pool_size;
@Value("${hibernate.jdbc.fetch_size}")
private String fetch_size;
@Value("${hibernate.dialect}")
private String dialect;
@Value("${hibernate.connection.driver_class}")
private String driver;
@Value("${hibernate.connection.url}") @Value("${hibernate.connection.url}")
private String url; private String url;
@Value("${hibernate.connection.username}") @Value("${hibernate.connection.username}")
private String username; private String username;
@Value("${hibernate.connection.password}") @Value("${hibernate.connection.password}")
private String password; private String password;
@Value("${hibernate.connection.driver_class}")
private String driver;
private LocalSessionFactoryBean sessionFactoryBean; private LocalSessionFactoryBean sessionFactoryBean;
@ -49,9 +56,14 @@ public class HibernateConfig{
public void init() throws IOException { public void init() throws IOException {
log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password); log.info("数据库配置初始化\nurl="+url+"\nusername="+username+"\npassword="+password);
sessionFactoryBean=new LocalSessionFactoryBean(); sessionFactoryBean=new LocalSessionFactoryBean();
Properties properties=new Properties();
properties.setProperty("hibernate.connection.pool_size",pool_size);
properties.setProperty("hibernate.jdbc.fetch_size",fetch_size);
properties.setProperty("hibernate.dialect",dialect);
sessionFactoryBean.setDataSource(basicDataSource()); sessionFactoryBean.setDataSource(basicDataSource());
sessionFactoryBean.setPackagesToScan("org.pqh.core.model"); sessionFactoryBean.setPackagesToScan("org.pqh.core.model");
sessionFactoryBean.afterPropertiesSet(); sessionFactoryBean.afterPropertiesSet();
} }
@Bean("transactionManager") @Bean("transactionManager")

@ -24,22 +24,22 @@ public class BaseService<T extends AbstractModel> {
Class<T> tClass = (Class<T>) formModel.getClass(); Class<T> tClass = (Class<T>) formModel.getClass();
try { try {
switch (action) { switch (action) {
case Insert: case C:
case Update: case U:
baseDao.saveOrUpdate(formModel); baseDao.saveOrUpdate(formModel);
break; break;
case Select: case R:
T model = baseDao.get(tClass, formModel.primaryKey()); T model = baseDao.get(tClass, formModel.primaryKey());
return model == null ? "找不到主键=" + formModel.primaryKey() + "" : model.toString(); return model == null ? "找不到主键=" + formModel.primaryKey() + "" : model.toString();
case Delete: case D:
baseDao.delete(tClass, formModel.primaryKey()); baseDao.delete(tClass, formModel.primaryKey());
break; break;
} }
return action + " success"; return action.getEn() + " success";
} catch (Exception e) { } catch (Exception e) {
log.error(formModel.tableNote() + "进行" + action + "操作失败,原因是:" + e.getMessage()); log.error(formModel.tableNote() + "进行" + action.getCh() + "操作失败,原因是:" + e.getMessage());
} }
return action + " fail"; return action.getEn() + " fail";
} }
} }

@ -4,8 +4,29 @@ package org.pqh.core.util;
* Created by reborn on 2017/8/2. * Created by reborn on 2017/8/2.
*/ */
public enum DBAction { public enum DBAction {
Insert,
Update, C("创建","Create"),
Delete,
Select U("更新","Update"),
R("读取","Retrieve"),
D("删除","Delete");
private String ch;
private String en;
DBAction(String ch, String en) {
this.ch = ch;
this.en = en;
}
public String getCh() {
return ch;
}
public String getEn() {
return en;
}
} }

@ -26,7 +26,7 @@ public class BaseController<T extends AbstractModel> {
@ResponseBody @ResponseBody
@RequestMapping(value = "{action}", produces = "text/html;charset=UTF-8") @RequestMapping(value = "{action}", produces = "text/html;charset=UTF-8")
public String curd(@PathVariable DBAction action, T model) { public String curd(@PathVariable DBAction action, T model) {
log.info(model.tableNote() + "进行" + action + "操作请求"); log.info(model.tableNote() + "进行" + action.getCh() + "操作请求");
return baseService.curd(action, model); return baseService.curd(action, model);
} }

@ -2,6 +2,6 @@ hibernate.connection.pool_size=5
hibernate.jdbc.fetch_size=50 hibernate.jdbc.fetch_size=50
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect hibernate.dialect=org.hibernate.dialect.MySQL57Dialect
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver
hibernate.connection.username=root
hibernate.connection.password=123456
hibernate.connection.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true hibernate.connection.url=jdbc:mysql://localhost:3306/bilibili?serverTimezone=UTC&&useSSL=true
hibernate.connection.username=root
hibernate.connection.password=0d4h0a3a
Loading…
Cancel
Save