ORM框架Bee的使用實例 (直接使用,及在MVC中使用)

1、直接用Bee的例子:java

public static void main(String[] args) {
        Suid suid=BeeFactory.getHoneyFactory().getSuid();
         
        Orders orders1=new Orders();
        orders1.setId(100001L);
        orders1.setName("Bee--ORM Framework");
        List<Orders> list1 =suid.select(orders1);  //select
         
        orders1.setName("Bee--ORM Framework");
        int updateNum=suid.update(orders1);   //update
        System.out.println("update record:"+updateNum);
         
        Orders orders2=new Orders();
        orders2.setUserid("bee");
        orders2.setName("Bee-ORM framework");
        orders2.setTotal(new BigDecimal(91.99));
        orders2.setRemark("");  //empty String test
         
        int insertNum=suid.insert(orders2); //insert
   }

2、Bee與Spring,Springmvc結合的例子:mvc

1.  第一個rest類app

@RequestMapping("/edit")
public Result update(Testnum testnum){
    Result  result =new Result();
    try{          
        int num=objSQLService.update(testnum);
        result.setTotal(num);
        if(num<=0) result.setErrorMsg("update failed!");
    } catch (BeeSQLException e) {
        result.setErrorMsg(e.getMessage());
    }
    return result;
}

 

2. 第二個rest類ui

@RequestMapping("/edit")
public Result update(TTest tTest){
    Result  result =new Result();
    try{          
        int num=objSQLService.update(tTest);
        result.setTotal(num);
        if(num<=0) result.setErrorMsg("update failed!");
    } catch (BeeSQLException e) {
        result.setErrorMsg(e.getMessage());
    }
    return result;
}

引入Bee,不一樣的rest類或Controller類或Action類,用的是同一個Bee實例做爲dao,簡單的業務還能夠用Bee包裝的統一的Service.rest

/**
 * @author AiTeaSoft.com
 * @since  1.1
 * Create on 2019-03-27 17:07:40
 */
@RestController
@RequestMapping("/testnum")
public class TestnumRest {
    @Autowired
    ObjSQLService objSQLService;
    @Autowired
    ObjSQLRichService objSQLRichService;
相關文章
相關標籤/搜索